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 ??
Button click and ListView click
Asked Answered
You want click on both? the item and button? –
Masakomasan
Yes, and go to diff activities –
Biforate
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.... thanks –
Biforate
possible duplicate of Android ListView with delete button –
Masakomasan
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"
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
© 2022 - 2024 — McMap. All rights reserved.