请帮忙.
解决方法 限制从网格中选择元素的目的可以如下完成:1.网格元素的创建.
<linearLayout androID:ID="@+ID/item_layout" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:gravity="center"> <ImageVIEw androID:ID="@+ID/imageVIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:src="@drawable/ic_launcher" /> <Radiobutton androID:ID="@+ID/radiobtn" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Image" /></linearLayout>
2.在自定义适配器的getVIEw()方法中填充此xml.
public class MyAdapter extends BaseAdapter { Context mCtx; int[] mimg; LayoutInflater layoutInflater; RadioGroup rgp; private Radiobutton mSelectedRB; private int mSelectedposition = -1; public MyAdapter(Context context,int[] img) { this.mCtx = context; this.mimg = img; rgp = new RadioGroup(context); layoutInflater = (LayoutInflater) mCtx .getSystemService(LAYOUT_INFLATER_SERVICE); } @OverrIDe public int getCount() { return mimg.length; } @OverrIDe public Object getItem(int position) { return null; } @OverrIDe public long getItemID(int position) { return 0; } @OverrIDe public VIEw getVIEw(final int position,VIEw convertVIEw,VIEwGroup parent) { VIEw vIEw = convertVIEw; Holder holder; if (vIEw == null) { vIEw = layoutInflater.inflate(R.layout.element,null); holder = new Holder(); holder.image = (ImageVIEw) vIEw.findVIEwByID(R.ID.imageVIEw); holder.radiobutton = (Radiobutton) vIEw .findVIEwByID(R.ID.radiobtn); vIEw.setTag(holder); } else { holder = (Holder) vIEw.getTag(); } holder.radiobutton.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if ((position != mSelectedposition && mSelectedRB != null)) { mSelectedRB.setChecked(false); } mSelectedposition = position; mSelectedRB = (Radiobutton) v; } }); if (mSelectedposition != position) { holder.radiobutton.setChecked(false); } else { holder.radiobutton.setChecked(true); if (mSelectedRB != null && holder.radiobutton != mSelectedRB) { mSelectedRB = holder.radiobutton; } } return vIEw; }}private class Holder { ImageVIEw image; Radiobutton radiobutton;}总结
以上是内存溢出为你收集整理的Android中网格视图的无线电组实施全部内容,希望文章能够帮你解决Android中网格视图的无线电组实施所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)