我正在研究listview,我想让在xml文件的textview中给出的文本可见。我在列表中添加的列表项显示正确(可见)但不是文本。我希望该文本可见也需要帮助。
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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:text="Name:"
android:visibility="visible"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="@+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:text="Gender:"
android:textColor="#FF00FF"
android:textSize="17sp"
android:textStyle="bold"
android:visibility="visible" />
</LinearLayout>
Java 代码:将数据放入适配器
if (success == 1) {
products = json.getJSONArray(TAG_PRODUCTS);
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
String gender = c.getString(TAG_GENDER);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_NAME, name);
map.put(TAG_GENDER, gender);
productsList.add(map);
}
public void run() {
ListAdapter adapter = new SimpleAdapter(
AllPersonActivity.this, productsList,
R.layout.list_item, new String[] { TAG_ID,
TAG_NAME, TAG_GENDER},
new int[] { R.id.pid, R.id.name, R.id.gender });
// updating listview
setListAdapter(adapter);
}
});