[英]How can I get RadioButton value from custom listview cells
我想從自定義列表視圖單元格中獲取數據,我有單選按鈕,並且試圖從中獲取數據,我該怎么做。
我的自定義列表代碼:
private class customList extends ArrayAdapter<String> {
public customList(Context context, int resource, List<String> objects) {
super(context, resource, objects);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflater.inflate(R.layout.custom_list , parent , false);
//ParseObject parseObject = new ParseObject("Questions");
//getParseData = new GetParseData(parseObject ,strQuestion);
// getParseData.getQuestion(position);
TextView tv = (TextView)row.findViewById(R.id.tvNameC);
tv.setText(nameList.get(position).toString());
final RadioGroup rg = (RadioGroup)row.findViewById(R.id.rg);
ParseQuery<ParseObject> query = ParseQuery.getQuery("test");
query.whereExists("arr");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject>List, ParseException e) {
if (e == null) {
strList = List.get(position).getList("arr");
Log.e("Array Is " , strList.toString());
final RadioButton[] radioButtons = new RadioButton[strList.size()];
for(int i = 0 ; i < radioButtons.length ; i++)
{
radioButtons[i] = new RadioButton(getApplicationContext());
radioButtons[i].setText(strList.get(i).toString());
radioButtons[i].setTextColor(Color.BLACK);
rg.addView(radioButtons[i]);
}
idForMethod = rg.getCheckedRadioButtonId();
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
return row ;
}
您可以在適配器中創建一個返回數據的方法。 例如,您可以使用狀態選擇單選按鈕填充列表。
public List<boolean> getSelectedBoxes() {
return selectedIds;
}
然后,假設您使用變量adapter
聲明了這個CustomAdapter,則可以在活動中按如下方式檢索它;
adapter.getSelectedBoxes();
您可以從適配器獲取數據,例如:
myListView =(ListView)findViewById(R.id.list);
//name of the class adapter with params
adapter=new LazyAdapter(this, mStrings,nombre);
myListView.setAdapter(adapter);
//event of click in listview
myListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getApplicationContext(), adapter.data[arg2], Toast.LENGTH_SHORT).show();
}
});
就我而言,當我單擊列表中的元素時,會顯示class.attribute [id / positon]
希望能有所幫助
for (int i = 0; i < Listview.getAdapter().getCount(); i++) {
View view = Listview.getAdapter().getView(i,Listview.getChildAt(i), Listview);
// View view = Listview.getChildAt(i);
TextView ref = (TextView)view.findViewById(R.id.tv_1);
EditText text = (EditText) view.findViewWithTag ("et"+i);
hmref.put("reference", ref.getText().toString());
Log.d("reference " + i, ref.getText()+"");
hmref.put("amount", text.getText().toString());
Log.d("amounts " + i, text.getText().toString());
sendlist.add(hmref);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.