Reputation: 2416
How to go to another Activity
when a Button
inside the ListView
is clicked
I have a custom list which I'm inflating it in getview()
and I'm also made the buttons clickable but how to move to another Activity
when button pressed.
Upvotes: 0
Views: 1230
Reputation: 1689
register your list activity under application tag in Android Manifest.xml file.
Upvotes: 0
Reputation: 234795
The trick to doing this is to add an OnClickListener
to your button inside the adapter's getView()
method and to use getTag()
and setTag()
to communicate the necessary data to the OnClickListener
. There's a detailed tutorial here about this and also this thread that talks about how it works for multiple buttons in a row.
Upvotes: 0
Reputation:
add this
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick() {
Intent i = new Intent(CurrentActivity.this, OtherActivity.class);
startActivity(i);
}
});
replace OtherActivity with the activity class name that you want to switch to.
Upvotes: 2