我知道这是一个转发,但我一直试图让这个工作几年(小时),我真的不明白现有的答案。 我想知道的是:如何编辑此代码以便它可以工作?我试图从两个不同的数组中填充textview。如何使用自定义适配器
只有第二个适配器被读取并且第一个文本视图保持空白。
任何帮助都将不胜感激。
public void run() {
if (t.getState() == Thread.State.TERMINATED) {
adapter2 = new ArrayAdapter<String>(getApplicationContext(), R.layout.listlook, R.id.txtl2, names);
setListAdapter(adapter2);
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.listlook, R.id.txtl1, comments);
setListAdapter(adapter);
return;
} else {
h.postDelayed(this, 1000);
}
}}
, 1000);
}
在此先感谢。内Usercomments.xml
<ListView
android:id="@+android:id/list"
android:layout_width="match_parent"
android:layout_height="150dp" >
</ListView>
listlook.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txtl1"
android:paddingLeft="2dp"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#0000FF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/txtl2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtl1"
android:gravity="bottom|right"
android:paddingLeft="5dp"
android:text="TextView"
android:textColor="#5C002E"
android:textSize="15sp" />
</RelativeLayout>
listlook
列表视图仅仅是我在ListView使用的布局?真的不知道我在做什么。
的适配器连接到一个ListView。我猜你的活动只有一个ListView,因为每个ListView只能有一个适配器,所以你用第二个适配器替换你的第一个适配器。看起来只有第二个适配器被使用。如果你想同时显示,你可能想要添加另一个ListView,或将两个列表放入一个,然后重试。 –
嘿丹尼尔,我使用了两个textview的自定义列表视图,但我有点自学成能,并不能淡化关于这种类型的事物的现有代码的一个字。感谢您的回复:) – dkgeld
我认为问题是,你不明白在适配器listView <->背后的想法。 ListView没有TesxViews的特定计数。你能显示listLook布局吗? –