setListAdapter不在ListActivity中显示我的String数组

|| list_item.xml:http://pastebin.com/bn56L3NN 在onCreate()之后和创建Comm对象之后发生的事情是,我收到一个“建立连接”消息,该消息在另一个线程中被拾取,并且在ReceiveMessage中得到该消息,然后发送“ list”并得到再次调用回receiveMessage。 我已经检查过Log.v,但确实得到了我想列出的消息,但问题是当我到达这些行时我无法在ListActivity中显示它,也许我应该将它们替换为某些内容其他?:
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, userRooms));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
完整代码:
package elf.app;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import elf.app.comm.CommClient;
import elf.app.comm.CommListener;
import elf.app.entity.ELFList;
import elf.app.entity.Entry;

public class RoomListActivity extends ListActivity implements CommListener {
    private ELFList eList;
    private String[] userRooms;
    private CommClient comm;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        eList = new ELFList();
        comm = new CommClient(  getIntent().getExtras().getString(\"ip\"),
                                getIntent().getExtras().getInt(\"port\") );
        comm.setListener(this);
        new Thread(comm).start();
    }

    public void receiveMessage(String IP, String message, int id) {
        if(message.equals(\"Connection established\")) {
            comm.send(\"list\");
        }
        if(message.charAt(0)==\'#\') {
            String[] strArr = toStringarr(message);
            eList.add(strArr);
            listItems();
        }
    }

    public String[] toStringarr(String str) {
        String substr = str.substring(1);
        return substr.split(\"@\");
    }

    public void listItems() {
        userRooms = eList.returnNames();

        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, userRooms));
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Entry e = eList.getEntry(position);
                String roominfo = e.toString();

                Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
                intent.putExtra(\"entry\",roominfo);
                intent.putExtra(\"ip\", getIntent().getExtras().getString(\"ip\"));
                intent.putExtra(\"port\", getIntent().getExtras().getInt(\"port\"));
                comm.disconnect();
                RoomListActivity.this.startActivity(intent);
            }
        });
    }

}
    
已邀请:
您忘记在
onCreate()
中为
Activity
设置内容视图,其中包含
Activity
的布局。因此,没有要显示的列表可以显示任何内容。在布局XML文件中定义一个布局,然后使用
setContentView()
将其设置为内容视图。     

要回复问题请先登录注册