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?
- 
                    Your question is not clear. What do you call "to go next layout" ? – Snicolas Aug 02 '11 at 13:56
- 
                    You have to learn intents and Listeners first! – Andro Selva Aug 02 '11 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 02 '11 at 14:01
5 Answers
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().
 
    
    - 37,646
- 24
- 106
- 138
Android ListView and ListActivity - Tutorial can help you to how to use the list with onitemclick.
 
    
    - 30,738
- 21
- 105
- 131
 
    
    - 5,814
- 10
- 39
- 60
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
See Stack Overflow question ListView without ListActivity. There's some example code from my application that works well.
 
     
     
     
    