0

I have a ListView. on click of a list item I start a Activity. Now I have added a Button on that ListView and onclick of a button I want to start a another activity. After adding a Button, I can click on the button and start a Activity but now I can not click a list item. What happened to listview's item click ??

βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
user533844
  • 2,053
  • 7
  • 36
  • 43
  • You want click on both? the item and button? – Ron Sep 23 '11 at 18:06
  • Yes, and go to diff activities – user533844 Sep 23 '11 at 18:13
  • post the code related to clickListeners of the button and the list item. – Urban Sep 23 '11 at 18:16
  • public void onItemClick(AdapterView> adapterView, View v, int arg2, long arg3) { Intent i = new Intent(getBaseContext(), TaskDetails.class); i.putExtra("TaskID", cursor.getString(cursor.getColumnIndex("TaskID"))); i.putExtra("EmpID", empid); startActivity(i); } }); – user533844 Sep 23 '11 at 18:17
  • android:onClick="myClickHandler" – user533844 Sep 23 '11 at 18:18
  • public void myClickHandler(View v) { Context context = getApplicationContext(); String url = "http://medev01.aa.com"; Intent i = new Intent(Intent.ACTION_VIEW); Uri u = Uri.parse(url); i.setData(u); try { startActivity(i); } catch (ActivityNotFoundException e) { Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT); } } – user533844 Sep 23 '11 at 18:19
  • Now add all that code to your question using the edit option. – Ron Sep 23 '11 at 18:21
  • I guess .... that's not a good idea. I changed my approch. anyways.... thanks – user533844 Sep 23 '11 at 18:29
  • possible duplicate of [Android ListView with delete button](http://stackoverflow.com/questions/3750380/android-listview-with-delete-button) – Ron Sep 23 '11 at 18:29

2 Answers2

9

Read this excellent blog post: Focus problems with list rows and ImageButtons

Essentially you should add the following to your root layout element in the row-item xml.

android:descendantFocusability="blocksDescendants"

tidbeck
  • 2,363
  • 24
  • 35
0

that is the concept. If u want to implement both clicks then write button click normally and for list item click did not use the listitem click.

Instead that you write onclick listener for converted view that you returned in getview()

Then both clicks will work

harish
  • 255
  • 1
  • 3
  • 13