0

I've created a listview extending Activity (only). I want to go to the next layout when I press the contents in listview. What can I do for this?

3
  • Your question is not clear. What do you call "to go next layout" ?
    – Snicolas
    Aug 2, 2011 at 13:56
  • You have to learn intents and Listeners first! Aug 2, 2011 at 14:00
  • Snicolas, it's not that important. What he needs is a clicklistener, and then he get put whatever he wants in that.
    – Rob
    Aug 2, 2011 at 14:01

5 Answers 5

1

Android ListView and ListActivity - Tutorial can help you to how to use the list with onitemclick.

1

When you create the view for each row in your ListAdapter. You can register a OnClickListener that will be called when the user clicks on the row.

 View view = inflater.inflate(R.layout.favorite_row, null);
 view.setOnClickListener( new View.OnClickListener() {
     Override
     public void onClick(View view) {
         beverageSelected( ((FavoriteBeverageView)view.getTag()).getFavoriteBeverage() );
     }
 });
 view.setTag( new FavoriteBeverageView( view ) );

Using setTag and setId can help you find the object in your list that the user selected. Personally I think it's easiest to use setTag() adding a special object that contains the UI elements within your List row (for example titleTextView, subtitleTextView, image, etc), and add a pointer to the backing object in that special object.

In the example above the FavoriteBeverageView is that special object, and within him there is a FavoriteBeverage object that is the data that backs that list. So in the OnClickListener can easily get the FavoriteBeverage back by just doing a ((FavoriteBeverageView)view.getTag()).getFavoriteBeverage().

0

You use the onItemClick() for that.

0

You will want to use OnClickListener

public OnClickListener myClickListener = new OnClickListener() { 
public void onClick(View v) {                 
 //code here that specifies what layout to go to.
   }

EDIT: I found this SO question that may contain some more information for you.

Also, if you would like to learn about intents and loading new views you can take a look at this tutorial

0

See Stack Overflow question ListView without ListActivity. There's some example code from my application that works well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.