我尝试使用列表视图来显示数据,但此代码不起作用。它不会产生错误,也不会在列表数据中显示数据。Chat类是适配器的 bean
Chat[] chat_obj=new Chat[cur.getCount()];
int i=0;
while(cur.moveToNext()){
chat_obj[i]=new Chat();
chat_obj[i].content=cur.getString(3);
i++;
}
ListView ll = (ListView)findViewById(R.id.contain);
listChat adapter=new listChat(this, chat_obj);
ll.setAdapter(adapter);
课堂聊天:
public class Chat {
String content;
String created_time;
}
适配器的类 listChat
public class listChat extends ArrayAdapter<Chat>{
private final Chat[] chat_obj;
private final Activity MyContext;
public listChat(Activity context, Chat[] obj){
super(context, R.layout.item);
this.chat_obj=obj;
this.MyContext=context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = MyContext.getLayoutInflater();
View rowView = inflater.inflate(R.layout.item, null, true);
TextView content=(TextView)rowView.findViewById(R.id.content);
content.setText("xxxxxxxxxxx");
return rowView;
}
}
文件 item.xml 中的布局 XML 项
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="xxx"/>
</LinearLayout>
请帮我!!