Click here to Skip to main content
12,949,601 members (70,937 online)
Rate this:
 
Please Sign up or sign in to vote.
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 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2017
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