Note that there are some explanatory texts on larger screens.

plurals
  1. POCode does not extend ListViewActivity, but does have a listview
    primarykey
    data
    text
    <p>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.</p> <p>My code does not extend the ListViewActivity but does have a listview as part of a relative layout which sits within a tabhost.</p> <p>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.</p> <p>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.</p> <p>My Main.xml is this :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost_master" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="65px" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingTop="65px"&gt; &lt;RelativeLayout android:id="@+id/tab1" android:orientation="vertical" android:layout_height="fill_parent" android:weightSum="1" android:gravity="top" android:layout_width="fill_parent"&gt; &lt;TextView android:text="Morning Set Up" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"&gt;&lt;/TextView&gt; &lt;Button android:text="Set Time On" android:layout_height="wrap_content" android:id="@+id/startb" android:layout_width="wrap_content" android:layout_below="@+id/textView1" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt; &lt;Button android:text="Set Time Off" android:layout_height="wrap_content" android:id="@+id/stopb" android:layout_width="wrap_content" android:layout_alignTop="@+id/startb" android:layout_alignParentRight="true"&gt;&lt;/Button&gt; &lt;Button android:layout_width="wrap_content" android:text="Set Days" android:id="@+id/mset_days" android:layout_height="wrap_content" android:layout_below="@+id/startb" android:layout_centerHorizontal="true"&gt;&lt;/Button&gt; &lt;Button android:id="@+id/confirm_m" android:layout_height="wrap_content" android:text="Confirm" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt; &lt;Button android:id="@+id/cancel_m" android:layout_height="wrap_content" android:text="Cancel" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days" android:layout_alignParentRight="true"&gt;&lt;/Button&gt; &lt;ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/listView1" android:layout_below="@+id/mset_days" android:layout_alignParentLeft="true" android:layout_marginTop="34dp"&gt;&lt;/ListView&gt; &lt;/RelativeLayout&gt; &lt;RelativeLayout android:id="@+id/tab2" android:orientation="vertical" android:layout_height="fill_parent" android:weightSum="1" android:gravity="top" android:layout_width="fill_parent"&gt; &lt;TextView android:text="A Set Up" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView1_a" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"&gt;&lt;/TextView&gt; &lt;Button android:text="Set Time On" android:layout_height="wrap_content" android:id="@+id/startb_a" android:layout_width="wrap_content" android:layout_below="@+id/textView1_a" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt; &lt;Button android:text="Set Time Off" android:layout_height="wrap_content" android:id="@+id/stopb_a" android:layout_width="wrap_content" android:layout_alignTop="@+id/startb_a" android:layout_alignParentRight="true"&gt;&lt;/Button&gt; &lt;Button android:layout_width="wrap_content" android:text="Set Days" android:id="@+id/mset_days_a" android:layout_height="wrap_content" android:layout_below="@+id/startb_a" android:layout_centerHorizontal="true"&gt;&lt;/Button&gt; &lt;TextView android:layout_height="wrap_content" android:text="Date / Time : \n Day \n Time" android:id="@+id/dandt_a" android:layout_width="wrap_content" android:layout_below="@+id/mset_days_a" android:layout_alignRight="@+id/mset_days_a" android:layout_marginTop="30dp"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/dandt2_a" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Along with this one as well" android:layout_below="@+id/dandt_a" android:layout_alignParentLeft="true" android:layout_marginLeft="14dp" android:layout_marginTop="44dp"&gt;&lt;/TextView&gt; &lt;TextView android:layout_height="wrap_content" android:text="To see if these text boxes clash" android:id="@+id/dandt3_a" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true"&gt;&lt;/TextView&gt; &lt;Button android:id="@+id/confirm_after_a" android:layout_height="wrap_content" android:text="Confirm" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days_a" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt; &lt;Button android:id="@+id/cancel_after_a" android:layout_height="wrap_content" android:text="Cancel" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days_a" android:layout_alignParentRight="true"&gt;&lt;/Button&gt; &lt;/RelativeLayout&gt; &lt;/FrameLayout&gt; &lt;/TabHost&gt; </code></pre> <p>My layout for the listview is this :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;CheckBox android:text="Cancel ?" android:focusable="false" android:checked="false" android:layout_width="wrap_content" android:id="@+id/checkBox1" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"&gt;&lt;/CheckBox&gt; &lt;TextView android:layout_width="wrap_content" android:focusable="false" android:id="@+id/time_disp" android:layout_height="wrap_content" android:text="TextView" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/checkBox1" android:layout_marginLeft="16dp" android:layout_marginTop="15dp"&gt;&lt;/TextView&gt; &lt;CheckedTextView android:layout_width="wrap_content" android:focusable="false" android:layout_height="wrap_content" android:text="CheckedTextView" android:id="@+id/checkedTextView1" android:layout_alignTop="@+id/time_disp" android:layout_alignParentRight="true" android:layout_marginRight="18dp"&gt;&lt;/CheckedTextView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>My activity code is this :</p> <pre><code>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&lt;String&gt; adapter1 = new ArrayAdapter&lt;String&gt;(this,R.layout.,R.id.time_disp,times); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(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&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Toast.makeText(getApplication().getApplicationContext(), "ID :"+Long.toString(arg3), Toast.LENGTH_LONG).show(); } }); } } </code></pre> <p>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:</p> <ul> <li><a href="https://stackoverflow.com/questions/3267517/question-about-onlistitemclick-in-listactivity">Question about onListItemClick in ListActivity</a></li> <li><a href="http://android-codes-examples.blogspot.com/2011/03/multiple-listview-and-custom-listview.html" rel="nofollow noreferrer">http://android-codes-examples.blogspot.com/2011/03/multiple-listview-and-custom-listview.html</a></li> <li><a href="https://stackoverflow.com/questions/3267517/question-about-onlistitemclick-in-listactivity">Question about onListItemClick in ListActivity</a></li> <li><a href="http://www.anddev.org/extended_checkbox_list__extension_of_checkbox_text_list_tu-t5734.html" rel="nofollow noreferrer">http://www.anddev.org/extended_checkbox_list__extension_of_checkbox_text_list_tu-t5734.html</a></li> <li><a href="https://stackoverflow.com/questions/4590856/how-to-get-selected-items-from-multi-select-list-view">How to get Selected items from Multi Select List View</a></li> <li><a href="http://www.mubasheralam.com/tutorials/android/how-create-multiple-choice-list" rel="nofollow noreferrer">http://www.mubasheralam.com/tutorials/android/how-create-multiple-choice-list</a></li> <li><a href="http://appfulcrum.com/2010/09/12/listview-example-3-simple-multiple-selection-checkboxes/" rel="nofollow noreferrer">http://appfulcrum.com/2010/09/12/listview-example-3-simple-multiple-selection-checkboxes/</a></li> <li><a href="http://www.anddev.org/advanced-tutorials-f21/listview-and-multiple-selection-t48402.html" rel="nofollow noreferrer">http://www.anddev.org/advanced-tutorials-f21/listview-and-multiple-selection-t48402.html</a></li> <li><a href="https://stackoverflow.com/questions/5417339/android-listview-with-checkbox-and-all-clickable">Android ListView with Checkbox and all clickable</a></li> <li><a href="http://appfulcrum.com/2010/09/12/listview-example-3-simple-multiple-selection-checkboxes/" rel="nofollow noreferrer">http://appfulcrum.com/2010/09/12/listview-example-3-simple-multiple-selection-checkboxes/</a></li> <li><a href="http://www.mousetech.com/blog/?p=74" rel="nofollow noreferrer">http://www.mousetech.com/blog/?p=74</a></li> <li><a href="http://www.vogella.de/articles/AndroidListView/article.html#singlemulti" rel="nofollow noreferrer">http://www.vogella.de/articles/AndroidListView/article.html#singlemulti</a></li> <li><a href="http://www.vogella.de/articles/AndroidListView/article.html" rel="nofollow noreferrer">http://www.vogella.de/articles/AndroidListView/article.html</a></li> </ul> <p>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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload