SimpleAdapter, показывающий пустой список

Код компилируется без ошибок, но в результате получается пустой список на моем телефоне. Так в чем проблема? Вот мой метод onCreate в Activity

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView textView;
    ArrayList<HashMap<String, String>> list=new ArrayList<HashMap<String, String>>();
    HashMap<String, String> m;
    for(int i=0; i<=10; i++) {
        m=new HashMap<String, String>();
        m.put("key", "value"+i);
        list.add(m);
    }
    String[] from={"key"};
    int[] to={R.id.text1};
    ListView lv=(ListView)findViewById(R.id.listView);
    SimpleAdapter sa=new SimpleAdapter(this, list, R.layout.row, from, to);        
    lv.setAdapter(sa);

main.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:id="@+id/listView"
    />
</LinearLayout>

row.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView android:layout_width="0px" android:layout_height="fill_parent"
              android:id="@+id/text1"
              android:text="dddddddd"
            />    
</LinearLayout>

1 ответ

Решение

В row.xml, менять

<TextView android:layout_width="0px" android:layout_height="fill_parent"

в

<TextView android:layout_width="wrap_content" android:layout_height="fill_parent"

Ширина 0px сделает вид невидимым и должен использоваться только в сочетании с layout_weight

Другие вопросы по тегам