Reputation: 49
I have a button, here is the code:
Button bHotel = (Button)findViewById(R.id.bHotel);
bHotel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainMenu.this, HotelList.class);
startActivity(intent);
}
});
If i click that button, my intention it will go to:
public class HotelList extends ListActivity{
........
}
My question is why my application has stopped unexpectedly, but if i change the extends to Activity not ListActivity it run just fine.
In manifest i register the HotelList class as an Activity
<activity android:name=".HotelList" android:label="@string/app_name" />
Any idea why it doesn't work?
Upvotes: 0
Views: 1004
Reputation: 2934
In case of ListActivity there is no need to setContentView(R.layout.xml_file_name);
. I think you use in HotelList class above line as setContentView(R.layout.xml_file_name);
. Remove line it will work.
From documentation Screen Layout
ListActivity has a default layout that consists of a single, full-screen list in thecenter of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)
Upvotes: 1
Reputation: 8604
Did you use setContentView method in your second activity? If so remove it since your activity extends ListActivity, also how did you populate your list? I think there is a problem with the way you declared the id of the ListView, it has to be "@android:id/list" or else it won't work.
Upvotes: 0
Reputation: 25761
If you are using your own layout, ListActivity expects a ListView inside the layout with id "@android:id/list"
. Make sure that you have a ListView declared in your layout and that the id of that ListView is "@android:id/list"
Upvotes: 0