简体   繁体   English

如何从自定义列表视图单元格获取RadioButton值

[英]How can I get RadioButton value from custom listview cells

I'm trying to get data from my custom list view cells , I have radio buttons and I'm trying to get the data from them how can I do that 我想从自定义列表视图单元格中获取数据,我有单选按钮,并且试图从中获取数据,我该怎么做。

My Custom List code : 我的自定义列表代码:

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 ;

}

You can creaate a method in your adapter that returns the data. 您可以在适配器中创建一个返回数据的方法。 For example, you can fill a list with the status selected radio buttons. 例如,您可以使用状态选择单选按钮填充列表。

public List<boolean> getSelectedBoxes() {
    return selectedIds;
}

Then, I assume that you declared this CustomAdapter with the variable adapter , you can retrieve this in your activity as follows; 然后,假设您使用变量adapter声明了这个CustomAdapter,则可以在活动中按如下方式检索它;

adapter.getSelectedBoxes();

you could get the data from an adapter for ex: 您可以从适配器获取数据,例如:

 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();

            }
        });

In my case, when I click an element of the list shows me class.attribute[id/positon] 就我而言,当我单击列表中的元素时,会显示class.attribute [id / positon]

Hope that helps 希望能有所帮助

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM