0

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 ;

}
karan
  • 8,637
  • 3
  • 41
  • 78

3 Answers3

0

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.getSelectedBoxes();
Faruk Yazici
  • 2,344
  • 18
  • 38
0

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]

Hope that helps

Kelo Adler
  • 13
  • 3
0
 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);
             }
bummi
  • 27,123
  • 14
  • 62
  • 101
Mihir Lakhia
  • 138
  • 1
  • 10