Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android
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 17-Jul-11 4:29am
Maxdd 71.5K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

one of the functions returns a string using the getString() of that class.
 
check this: search for "checkbox in listview" [^]@ android developer group @ google
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It should be used a listview with multiple choice mode
 
http://developer.android.com/reference/android/widget/AbsListView.html#CHOICE_MODE_MULTIPLE[^]
 
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);
  }
  Permalink  
Comments
Maxdd 7 at 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)

  Print Answers RSS
0 OriginalGriff 6,769
1 Sergey Alexandrovich Kryukov 6,338
2 DamithSL 5,408
3 Manas Bhardwaj 4,816
4 Maciej Los 4,195


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100