Click here to Skip to main content
11,634,796 members (67,747 online)
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 3: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 8,736
1 Sergey Alexandrovich Kryukov 8,419
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2015
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