
我在每行中都有一个自定义列表视图和一个单选按钮,它可以正常工作,但是我想从此代码中访问选定单选按钮的ID.例如,当我需要选定行的textvIEw1值时,如何收集它?提前致谢.这是我的代码:
private static class Adapter extends BaseAdapter { private LayoutInflater mInflater; private int mResourceID = 0; private Radiobutton mSelectedRB; private int mSelectedposition = -1; public CitiZenAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return array.size(); } public Object getItem(int position) { return position; } public long getItemID(int position) { return position; } public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) { final VIEwHolder holder; if (convertVIEw == null) { convertVIEw = mInflater.inflate(R.layout.table_row_citiZen, null); holder = new VIEwHolder(); holder.text1 = (TextVIEw) convertVIEw.findVIEwByID(R.ID.TextVIEw01); holder.text2 = (TextVIEw) convertVIEw.findVIEwByID(R.ID.TextVIEw02); holder.button = (Radiobutton)convertVIEw.findVIEwByID(R.ID.radiobuttonCitiZen); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); } holder.text1.setText(array1.get(position)); holder.text2.setText(array2.get(position)); holder.button.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if((position != mSelectedposition && mSelectedRB != null)){ mSelectedRB.setChecked(false); } mSelectedposition = position; mSelectedRB = (Radiobutton)v; } }); if(mSelectedposition != position){ holder.button.setChecked(false); }else{ holder.button.setChecked(true); if(mSelectedRB != null && holder.button!= mSelectedRB){ mSelectedRB = holder.button; } } return convertVIEw; } static class VIEwHolder { TextVIEw text1; TextVIEw text2; Radiobutton button; } }解决方法:
I want to reach ID of selected radio button from this code.
您必须使用setTag&获取getTag属性以获取所选单选按钮的实际ID,
holder.button.setTag(position); holder.button.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { int pos = (Integer) v.getTag(); Log.i("ID of radiobutton","Order Edit @ position : " + pos); String _Str1=array1.get(pos); String _Str2=array2.get(pos); } }); 这样,您将从行中获取textvIEw的确切值.
总结以上是内存溢出为你收集整理的从Android中的自定义列表获取单选按钮值全部内容,希望文章能够帮你解决从Android中的自定义列表获取单选按钮值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)