0

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.

user
  • 86,916
  • 18
  • 197
  • 190
Girish
  • 2,196
  • 2
  • 18
  • 24

3 Answers3

2

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.

0

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.

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • @Girish - You should mark this thread as solved. (Click on the check mark next to the answer that provided the solution.) – Ted Hopp Mar 08 '12 at 16:29
0

register your list activity under application tag in Android Manifest.xml file.

DineshKumar
  • 1,641
  • 15
  • 13