1

私はリストビューに取り組んでいます.xmlファイルのテキストビューで指定されたテキストを表示したいと考えています。リストに追加したリスト項目は正しく表示されていますが (表示されます)、テキストは表示されません。そのテキストを表示したいので、助けが必要です。

ここに画像の説明を入力

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);
                }
            });
4

4 に答える 4

0

IMHO LinearLayout の同じ背景色とコンテンツのフォント色が原因です。次のコードを試してください

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
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:textColor="@android:color/white"
    android:textSize="17sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/gender"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/white"
    android:paddingLeft="6dip"
    android:paddingTop="6dip"
    android:text="Gender:"
    android:textColor="#FF00FF"
    android:textSize="17sp"
    android:textStyle="bold"
    android:visibility="visible" />

于 2013-09-25T07:37:28.253 に答える
0

リストビューに入力されたデータをテキストに追加できます。

つまり、YourTextView.setText("Name: " + listitem);

このような。最も簡単な方法です。

于 2013-09-25T09:42:33.247 に答える
0

私のような問題に直面している人々を助けるために、私自身の質問に答えます。私は解決策を見つけましたが、それは良いものではありませんが、私にとってはうまくいきました。別の方法に変更すると、Viewsテキストやその他のものを別の方法で表示するのに役立ちます。問題は、コード (アダプター) が解析された文字列を置き換えていたxml TextViewsためTextView、リストから取得した各項目の上に別の項目を配置したことでした。

ここに私が変更したXMLがあります

<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" />


    <!--This is to show the label "Name" above the listitem (whatever name) come from java code parsed, json  -->

    <TextView
        android:id="@+id/txtshowname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceMedium" />


<!-- This TextView will contain the listitems loaded from server -->

     <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="6dip"
        android:paddingLeft="6dip"
        android:visibility="visible"
        android:textColor="@android:color/white"
        android:textSize="17sp"
        android:textStyle="bold" />



 <!--This is to show the label "Gender" above the listitem (whatever gender) come from java code parsed, json  -->
    <TextView
        android:id="@+id/txtshowGender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Gender"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="6dip"
        android:paddingTop="6dip"
        android:textColor="#FF00FF"
        android:textSize="17sp"
        android:textStyle="bold"
        android:visibility="visible" />

</LinearLayout>

また、この小さな変更は私にとってはうまくいきました

map.put(TAG_ID, id);
                    map.put(TAG_NAME, "Name" + name);
                    map.put(TAG_GENDER, "Gender" + gender);


                    productsList.add(map);
于 2013-09-25T08:21:04.093 に答える