You need to set an onItemClickListener for your ListView that will start another activity with the info of the row selected when the row is clicked (outside the CheckBox of course). I would recommend having your Activity implement AdapterView. OnItemClickListener which requires the method.
Up vote 0 down vote favorite 1 share g+ share fb share tw.
What I am trying to accomplish is to have a checkbox in each row, having the ability to check the box separately (for batch deleting) and being able to select the entire row to view data associated with the list item. I have done a checkbox with a textview but that only lets be select the box and I cant click on the list item to view that items data. I also used checkedTextView but that checks the box where ever you click on the row calling the onListItemClick and thats not what I want either.
Is there some what I can separate checking the box from clicking a listview item? Pretty much trying to do what the gmail app does when selecting messages to delete and view this is my row layout creating listview @Override public void onActivityCreated(Bundle state){ super. OnActivityCreated(state); lv = getListView(); lv.
SetChoiceMode(ListView. CHOICE_MODE_MULTIPLE); lv. SetItemsCanFocus(false); setEmptyText("No Bowlers"); registerForContextMenu(getListView()); populateList(); } EDIT: my populate method public void populateList(){ String fields = new String {BowlersDB.
NAME}; //mAdapter = new CheckAdapter(getActivity(),R.layout. Check_listview,null,fields,new int {R.id. NameCheckTV}); mAdapter = new SimpleCursorAdapter(getActivity(),R.layout.
Check_listview,null,fields, new int {R.id. NameCheckTV}); setListAdapter(mAdapter); getLoaderManager(). InitLoader(0,null,this); } android listview checkbox link|improve this question edited Jan 17 at 19:27 asked Jan 17 at 16:17tyczj525312 98% accept rate.
You need to set an onItemClickListener for your ListView that will start another activity with the info of the row selected when the row is clicked (outside the CheckBox of course). I would recommend having your Activity implement AdapterView. OnItemClickListener which requires the method public void onItemClick(AdapterView parent, View view, int position, long id) {} Inside this method you can launch an Activity with details corresponding to the data in the row selected.
Hopefully I understood your question correctly.
I had a strange workaround with this issue. Here is my solution. Use this for your ListView.
Product is just a model object to hold your data in this case: public class CatalogItemAdapter extends ArrayAdapter // { private ArrayList products; private Activity activity; public CatalogItemAdapter(Context context, int textViewResourceId, ArrayList items, Activity activity) // { super(context, textViewResourceId, items); this. Products = items; this. Activity = activity; } @Override public View getView(int position, View convertView, ViewGroup parent) // { Product product = products.
Get(position); if (convertView == null) // { LayoutInflater vi = (LayoutInflater) activity . GetSystemService(Context. LAYOUT_INFLATER_SERVICE); convertView = vi.
Inflate(R.layout. Catalog_item_stub, null, false); } } } Somewhere in your onResume(), put this: listView = (ListView) activity. FindViewById(R.id.
CatalogProducts); m_adapter = new CatalogItemAdapter(activity, R.layout. Catalog_item_stub, products, activity); if (products == null) products = new ArrayList(); listView. SetAdapter(m_adapter); R.layout.
Catalog_item_stub is a layout stub created in XML like so (put the appropriate items in it for you, like the checkbox): Hopefully this helps! Holler if you need any clarification.
– tyczj Jan 17 at 17:25 You can use your own custom elements and do whatever you want with them. This means you can handle everything manually and have it behave as you like. – Pheonixblade9 Jan 17 at 17:26 @tyczj take a look at the small change I made.
It should make it a little more clear what I'm talking about. – Pheonixblade9 Jan 17 at 17:28.
The issue is that Android doesn't allow you to select list items that have elements on them that are focusable. Try modifying the checkbox on the list item: android:focusable="false.
The gmail app uses its own view called CanvasConversationHeaderView that manages its subviews. This method is probably more heavy-weight than what you are looking for. An easier method would be to make the checkbox not "focusable" (as Alex Lockwood suggests) and then attach an onClick in the XML.
Then in your activity code add public void onCheckboxClicked(View view) { RelativeLayout rl = (RelativeLayout)view.getParent(); Log. D(TAG, "Checkbox clicked! GetTag returned: " + rl.getTag()); } EDIT: How to add a tag from SimpleCursorAdapter.
BindView private class MyCursorAdapter extends SimpleCursorAdapter { public MyCursorAdapter(Context context, int layout, Cursor c, String from, int to) { super(context, layout, c, from, to); } @Override public void bindView(View view, Context context, Cursor cursor) { //Log. D(TAG, "Cursor pos: " + cursor.getPosition()); String name = cursor. GetString( cursor.
GetColumnIndex(ContactsContract.Contacts. DISPLAY_NAME)); view. SetTag(name); super.
BindView(view, context, cursor); } } Note: I set the tag to the View from the bindView call, which is the RelativeLayout at the root of your xml. Look at the onCheckboxClicked method to see how I got the tag.
I did try using an onClick method at first but I cant get the id of the items selected for deletion. The only way I would be able to do that is to set a listener on the checkbox in my adapter and keep a running array of id's – tyczj Jan 17 at 17:47 You can try using the view's setTag and getTag methods for attaching meaning to each one. In your ListAdapter when you populate the row, just add view.
SetTag(new Integer(position)). (Note that this would set the tag of the RelativeLayout, so you can either do a view. FindViewById(R.id.
CheckBox1).setTag() or in the onClick you can get the parent of the checkBox to get the relativeLayout that owns the checkbox. ) – MikeC Jan 17 at 18:22 I use a cursor to populate the listview from a database though, would that change anything? Also updated first post with my populate list method – tyczj Jan 17 at 19:26 I haven't tried this yet, but you could override the cursor adapter to add the tag when it is populating the view.
For the methods you have to override, just call the super method and then add your own code to set the tag to the view created. – MikeC Jan 17 at 19:56 ok so I tried setting a tag in the bindView of the adapter with view. SetTag(name) name is a string from the cursor but when I click on the checkbox and the onclick gets called I get a NullPointer on the Object name = view.getTag().
Did I do that right? – tyczj Jan 177 at 3:34.
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.