【发布时间】:2013-10-20 20:06:25
【问题描述】:
我知道这是一个转贴,但我一直试图让它工作多年(几个小时),我真的无法理解现有的答案。 我只想知道:如何编辑此代码以使其正常工作?我正在尝试从两个不同的数组填充两个文本视图。
只有第二个适配器被读取,第一个的 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);
}
提前致谢。
Usercmets.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 只能有 1 个适配器,所以您正在用 Seconds 替换您的第一个适配器。看起来只使用了第二个适配器。如果您想同时显示两者,您可能需要添加另一个 ListView,或者将两个 List 合而为一,然后重试。
-
嘿,Daniel,我正在使用带有两个文本视图的自定义列表视图,但我有点自学成才,无法理解现有代码中有关此类事物的任何内容。感谢您的回复:)
-
我认为问题在于,您不了解 listView 适配器背后的想法。 ListView 没有特定的 TesxView 计数。你能显示 listLook 布局吗?
标签: android android-arrayadapter listadapter