tags:

views:

1624

answers:

3

Hi, i think ive tried everything(made focusable:false!!) and i cant capture in anyway the selected checkbox on my list item. even OnItemClickListener, doesnt respond to any click.

how can i retrieve checked checkboxes in my list item? my list item inclused: image view, 4 textviews and the checkbox

some code:

this is in my ListActivity class:

final String columns[] = new String[] { MyUsers.User._ID, 
        MyUsers.User.MSG, MyUsers.User.LOCATION }; 

int[] to = new int[] { R.id.toptext, R.id.bottomtext,R.id.ChkBox, R.id.Location};

Uri myUri = Uri.parse("content://com.idan.datastorageprovider/users"); 

Cursor cursor = getContentResolver().query(myUri, columns, null, null, null);   

            startManagingCursor(cursor);   


ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this, 
        R.layout.listitem, cursor, columns, to); 

 this.setListAdapter(myCursorAdapter); 

and this is my Custom Cursor adapter class:

public class ListCursorAdapter extends SimpleCursorAdapter
{

 private Context context; 
 private int layout; 

 public ListCursorAdapter(Context context, int layout, Cursor c, 
    String[] from, int[] to) 
{ 
   super(context, layout, c, from, to); 
   this.context = context; 
   this.layout = layout; 

} 

@Override 
public View newView(Context context, Cursor cursor, ViewGroup parent) 
{ 

   Cursor c = getCursor(); 

   final LayoutInflater inflater = LayoutInflater.from(context); 
   View v = inflater.inflate(layout, parent, false); 
           return v; 
} 

@Override
public void bindView(View v, Context context, Cursor c) 
{ 
    TextView topText = (TextView) v.findViewById(R.id.toptext); 
    if (topText != null) 
    { 
        topText.setText(""); 
    } 

    int nameCol = c.getColumnIndex(MyUsers.User.MSG); 
    String name = c.getString(nameCol); 
    TextView buttomTxt = (TextView) v.findViewById(R.id.bottomtext); 
    if (buttomTxt != null) 
    { 
        buttomTxt.setText("Message: "+name); 
    } 

nameCol = c.getColumnIndex(MyUsers.User.LOCATION); 
name = c.getString(nameCol); 
TextView location = (TextView) v.findViewById(R.id.Location); 
if (locationLinkTxt != null) 
{ 
    locationLinkTxt.setText(name); 
} 

I will appreciate any help! it's really depressing, I've tried many ways. many listeners, can't figure how to capture listener to my checkboxes.

The data I am binding to the list items from the database, isn't concered about the checkbox.. only the textviews.. there isn't any connection between the database and the checkbox I have in the list's item.

Thanks, idan.

     <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100sp"
android:focusable="false" android:focusableInTouchMode="false">
android:padding="6dip">

<ImageView android:layout_width="wrap_content"
    android:layout_height="fill_parent" android:src="@drawable/icon"
    android:id="@drawable/icon" android:layout_marginLeft="6dip"
    android:focusable="false" android:focusableInTouchMode="false">


</ImageView>


<LinearLayout android:id="@+id/LinearLayout01"
    android:orientation="vertical" android:layout_width="1sp"
    android:layout_height="fill_parent" android:layout_weight="1"
    android:focusable="false" android:focusableInTouchMode="false">

    <TextView android:id="@+id/toptext" android:layout_weight="1"
        android:gravity="center_vertical" android:text="OrderNum"
        android:singleLine="true" android:layout_height="0dp"
        android:layout_width="wrap_content" android:focusable="false"
        android:focusableInTouchMode="false">

    </TextView>



    <TextView android:id="@+id/bottomtext" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:focusable="false"
        android:focusableInTouchMode="false" android:text="TweetMsg">
    </TextView>









    <TextView android:id="@+id/twittLocation"
        android:layout_weight="1" android:text="location" android:singleLine="true"
        android:layout_width="fill_parent" android:layout_height="0dip"
        android:focusable="false" android:focusableInTouchMode="false">
    </TextView>
    <TextView android:layout_weight="1" android:id="@+id/twittLocationlink"
        android:text="locationlink" android:gravity="fill_horizontal"
        android:layout_width="fill_parent" android:layout_height="0dip"
        android:focusable="false" android:focusableInTouchMode="false">
    </TextView>





</LinearLayout>




<CheckBox android:id="@+id/deleteTwittChkBox" android:text="Delete"
    android:layout_width="wrap_content" android:layout_marginRight="2dp"
    android:focusable="false" android:checked="false"
    android:focusableInTouchMode="false" android:layout_height="fill_parent"></CheckBox>

+1  A: 

I would recommend you use Android's built-in support for multiple-choice lists (CHOICE_MODE_MULTIPLE).

The List11.java SDK sample demonstrates this. You can also find a project from one of my tutorials that uses it here.

You can still use this technique with your own layout, so long as you include a CheckedTextView with android:id="@android:id/text1" as shown in the android.R.layout.simple_list_item_multiple_choice resource, a copy of which ships with your SDK.

CommonsWare
i`am not sure i understoond, what is the CheckedTextView connected o the idea of the checkbox listeners?ive tried to look some sample tutorials in that link, mybe u could give me a specific link for a specific tutorial?thank you,idan.
rayman
I am saying you should get rid of your "checkbox listeners". Design your UI around a standard multiple-choice `ListView`, where the user makes choices via the checkboxes, then you take action when the user indicates they are done (clicks the BACK button, clicks a "Next" `Button`, chooses a menu choice, etc.).
CommonsWare
Yes exaclly thats what i need in the scenario, ive got a button which deleting the items that have been checked, the prob is: how do i combine it with my Custom SimpleCurose.. or it's not connected to each other..could you pass me a specific link to one of your tutorials?so i can follow it..thanks again. }
rayman
so ive added those 3 lines as it seems in List11.java final ListView listView = getListView(); listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); but still how will i collect the items which thire checkboxes have been checked? thanks.
rayman
Call `getCheckedItemIds()` on your `ListView`
CommonsWare
okie i think i`am so closed to it to be done.. after ive done on a button press long [] items=listView.getCheckItemIds(); now ive selected in two items, the checkboxes they have in it. and the expression value of items after button click is: "items"= (id=830065282632) why doesnt it show me both of them..? thanks again.
rayman
If have no idea what "the expression value of items" means.
CommonsWare
i meant the value of the verb 'items' after executing items=listView.getCheckItemIds(); between ive edited my question and added the xml of row item. how should i adjust it? coz i got there two Linearlayouts.
rayman
Ive have examined the simple_list_item_multiple_choice.xml are you sure i can add more 'parts' to that example? i past my xml above, can i modify it and use it with the same logic? coz i need more parts in my list's item row, coz i`am binding data to each part in that row.
rayman
A: 

getCheckedItemIds()

But why does this not get changed when items are UNchecked in the ListView? I need to find out how to see only those items the user has checked, even after say selecting multiple items adn then unchecking a couple of them. The getCheckedItemIds() still shows ALL that were checked. So, not useful from that standpoint. what am I missing here?

AndroidCoder