Android sdk - ListView and checkboxes - revisited [SOLVED]?

Fixed this issue now , partly my misunderstanding on how the checkbox works with the listview and also understanding the behavior of the listview as well.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I know that there are a lot of posts about checkboxes within Listviews and I can honestly say that after reading a large majority of these, it has left me confused with a hurting brain. My code does not extend the ListViewActivity but does have a listview as part of a relative layout which sits within a tabhost. I have tried the focusable=false both against the textview and the checkbox, the textview behaves but the checkbox still overrides the focus of the listview item.

If I only needed one textview then I would have gone for androids built in layout but I require at least 6 textviews with a checkox on each line. My Main. Xml is this : My layout for the listview is this : My activity code is this : package co.uk.sheildsatmax. Layout_tester; import android.app.

Activity; import android.app. ListActivity; import android.os. Bundle; import android.view.

View; import android.widget. AdapterView; import android.widget.AdapterView. OnItemClickListener; import android.widget.AdapterView.

OnItemSelectedListener; import android.widget. ArrayAdapter; import android.widget. ListView; import android.widget.

TabHost; import android.widget.TabHost. TabSpec; import android.widget. Toast; import android.widget.

CheckBox; public class Layout_testerActivity extends Activity { /** Called when the activity is first created. */ private String times = {"09:10","10:10","11:20","09:10","12:20","15:30","10:12"}; ListView lv; CheckBox ticked; @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout.

Main); TabHost tabhost=(TabHost)findViewById(R.id. Tabhost_master); tabhost.setup(); TabSpec tab1 = tabhost. NewTabSpec("Tab1"); morning_tab.

SetContent(R.id. Tab1); morning_tab. SetIndicator("Tab1 Setup"); TabSpec tab2 = tabhost.

NewTabSpec("tab2"); after_tab. SetContent(R.id. Tab2); after_tab.

SetIndicator("Tab2 Setup"); tabhost. AddTab(tab1b); tabhost. AddTab(tab2); lv = (ListView)findViewById(R.id.

ListView1); // ArrayAdapter adapter1 = new ArrayAdapter(this,R.layout. ,R.id. Time_disp,times); ArrayAdapter adapter = new ArrayAdapter(this,R.layout.

List_lay,R.id. Time_disp,times); lv. SetItemsCanFocus(false); // this was another test attempt lv.

SetChoiceMode(ListView. CHOICE_MODE_MULTIPLE); // tried this and then realised it needed androids own layout to work lv. SetAdapter(adapter); lv.

SetOnItemClickListener(new AdapterView. OnItemClickListener() { @Override public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Toast. MakeText(getApplication().

GetApplicationContext(), "ID :"+Long. ToString(arg3), Toast. LENGTH_LONG).show(); } }); } } Now I have been reading about creating a separate class for the adapter to make the checkbox work correctly but is this required and if so could someone please post a basic example for me to use as all of these links I have read have really confused me (does not take much :) ): Question about onListItemClick in ListActivity http://android-codes-examples.blogspot.com/2011/03/multiple-listview-and-custom-listview.html Question about onListItemClick in ListActivity http://www.anddev.org/extended_checkbox_list__extension_of_checkbox_text_list_tu-t5734.html How to get Selected items from Multi Select List View co.

Uk0 co. Uk1 co. Uk0 Android ListView with Checkbox and all clickable co.

Uk1 co. Uk1 co. Uk0 co.

Uk1 as you can see I have read quite a few but they have puzzled me even more and none seem to have examples without listactivies. I am writing this in android 1.6 Kind regards TimCS android listview sdk checkbox link|improve this question edited Jan 29 at 20:54 asked Jan 24 at 14:01TimCS4115 100% accept rate.

I am going to re-attempt the examples from the anddev.org links and try and use these. Not sure though if they will work as I a not using extend ListActivity within my project as the Activity is also managing a tabhost as well. – TimCS Jan 27 at 12:16 I think I have found a better example of what I am after here anddev.org/other-coding-problems-f5/… so I will try this and see how I get on – TimCS Jan 27 at 13:41 tried the code from the above link, still have the issue where the checkbox takes over the focus of the listview.

Hmmm more thought needed here – TimCS Jan 28 at 23:34 think I understand now that the checkbox will always interact when clicked on but the list view line it sits on will still work. I have now managed to get the checkbox to be ticked when the list view line is clicked on as well. Furthermore I have learnt about the recycle habits of the listview.

– TimCS Jan 29 at 20:41.

Fixed this issue now , partly my misunderstanding on how the checkbox works with the listview and also understanding the behavior of the listview as well. I ended up using the example given on this thread at this forum -> managing multiple checkboxes With the help of this thread on this forum => Ticking checkboxes when clicking a listview line2 Finally got the listview to remember which checkbox is tick when scrolling up and down off the screen using => Keeping the checkbox state on listview recycle.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions