我有一个正在填充的ListView。我检查了数据源的内容,它包含有效数据。不幸的是,行数是正确的,但我想要显示的文本没有出现。
以下是我设置ListView的方法:
private void setupUI() {
setContentView(R.layout.streamactivity);
this.streamListView = (ListView) findViewById(R.id.streamListView);
this.streamAdapter = new StreamAdapter(this, R.layout.streamactivityrow, messages);
streamListView.setAdapter(this.streamAdapter);
}
这是我的适配器:
private class StreamAdapter extends ArrayAdapter<STMessage> {
private ArrayList<STMessage> messages;
public StreamAdapter(Context context, int textViewResourceId, ArrayList<STMessage> messages) {
super(context, textViewResourceId, messages);
this.messages = messages;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.streamactivityrow, null);
}
STMessage aMessage = messages.get(position);
if (aMessage != null) {
TextView titleText = (TextView) v.findViewById(R.id.toptext);
TextView descriptionText = (TextView) v.findViewById(R.id.bottomtext);
if (titleText != null) {
titleText.setText(aMessage.getBody());
}
if (descriptionText != null) {
descriptionText.setText(aMessage.getFor_user_login());
}
}
return v;
}
}
以下是列表中每行的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical" android:layout_height="0dip" android:singleLine="true" android:textSize="15sp" android:textStyle="bold" android:ellipsize="end" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#FFFFFF"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15sp" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#FFFFFF"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/dateText" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#E2E2E2"></TextView></LinearLayout>
</LinearLayout>
以下是使用ListView的StreamActivity的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/streamListView"></ListView>
</LinearLayout>
答案 0 :(得分:0)
请查看您的XML,有些值为0。
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
答案 1 :(得分:0)
罪魁祸首是:
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/streamListView"></ListView>
应为fill_parent
。