Click here to Skip to main content
15,888,212 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I was following the ListView official tutorial - [url]http://developer.android.com/resources/tutorials/views/hello-listview.html[/url], because I get the entries dinamically through a webservice.

Problem is, I want to place checkboxes at it. I have this

(aux (String [] aux) is previously and correctly fullfilled before this)
//setListAdapter(new ArrayAdapter<String>(this, R.layout.lista, aux));
        setListAdapter(new ArrayAdapter<CheckBox>(this,R.layout.row, convertToListItem(aux)));

        //ListView lv = getListView();
        //lv.setTextFilterEnabled(true);

And I think the problem is on my row.xml

<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:textSize="14sp" android:typeface="normal" android:textStyle="normal"

    android:layout_weight="0" android:layout_gravity="left" />

or in this function

private List<CheckBox> convertToListItem(String[] aux2){

        List<CheckBox> result = new ArrayList<CheckBox>();
        ArrayList<CheckBox> boxes = new ArrayList<CheckBox>();

        for (String text : aux2){
            CheckBox temp = new CheckBox(this);
            temp.append(text);
            temp.setText(text,BufferType.NORMAL);
            result.add(temp);
            boxes.add(temp);

        }


return result;
What happens is: it appears the checkbox, but in front instead the right text it appears "android.widget.Checkbox@...."

What am I doing wrong ?
Posted

one of the functions returns a string using the getString() of that class.

check this: search for "checkbox in listview" [^]@ android developer group @ google
 
Share this answer
 
It should be used a listview with multiple choice mode

http://developer.android.com/reference/android/widget/AbsListView.html#CHOICE_MODE_MULTIPLE[^]

XML
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setListAdapter(new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_multiple_choice, GENRES));

      final ListView listView = getListView();

      listView.setItemsCanFocus(false);
      listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  }
 
Share this answer
 
Comments
Maxdd 7 18-Jul-11 8:14am    
Much easier :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900