开发者

android: having two listviews in two listactivities didn't work

I guess my previous question wasn't clear enough ( Android: failed to setContentView when switching to ListActivity ), so I explain as follows.

In my app I have two listactivities which uses two different listviews:

public class Activity1 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    try{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview1); 
}
public class Activity2 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    try{
    super.onCreate(savedInstanceState);
    setContentView(开发者_StackOverflowR.layout.listview2); 
}

}

As required by android, listview must have an ID which is exactly "@android:id/list". If I set the listview in both listview1 and listview2 with the same ID, then they will end up using the same format of listview, which is not what I want. But if I set one of the IDs to be sth like "@+id/listview2", android gave me the error: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

How do I handle this dilema?

btw: my listview is sort of complicated, customed list with image icons and text, so in my code, I also extended the ListAdapter:

this.mListAdapter = new myListAdapter(this, 
            R.layout.listview1, mTiebaInfo);
     setListAdapter(this.mListAdapter);


Don't use ListActivities. Use Activities and have a ListView in the each xml which you can name however you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜