Button click and ListView click
Asked Answered
B

2

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 ??

Biforate answered 23/9, 2011 at 17:59 Comment(9)
You want click on both? the item and button?Masakomasan
Yes, and go to diff activitiesBiforate
post the code related to clickListeners of the button and the list item.Josephus
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); } });Biforate
android:onClick="myClickHandler"Biforate
public void myClickHandler(View v) { Context context = getApplicationContext(); String url = "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); } }Biforate
Now add all that code to your question using the edit option.Masakomasan
I guess .... that's not a good idea. I changed my approch. anyways.... thanksBiforate
possible duplicate of Android ListView with delete buttonMasakomasan
D
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"

Donnie answered 1/12, 2011 at 14:28 Comment(0)
A
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

Alphaalphabet answered 23/9, 2011 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.