Re: [問題] SimpleAdapter 與 ListView
謝謝版上的各位!!!
我的main.xml (簡寫)
<LinearLayout
<TextView
android:id="@+id/textView1"
<ListView
android:id="@+id/listView1"
我的java
當初發生問題是在這段
//新增SimpleAdapter
adapter = new SimpleAdapter(
this,
list,
android.R.layout.simple_list_item_2,
new String[] { "option","tv" },
new int[] {android.R.id.text1, android.R.id.text2} );
ListView1.setAdapter( adapter );
在第四行,我以為是要設在 R.layout.main 或 R.id.listView
後來直接依照網路上的寫法,就成功了 orz
※ 引述《lazior (懶人)》之銘言:
: main.xml:
: <LinearLayout
: <TextView android:id="@+id/textView" />
: <ListView android:id="@+id/listView"
: android:orientation="vertical"
: android:layout_width="wrap_content"
: android:layout_height="wrap_content"
: />
: </LinearLayout>
: activity.java:
: .....
: setContentView(R.layout.main);
: ListView list=(ListView)findViewById(R.id.ListView01);
: //抓取 LietView 的值
: ....
: 印象中是醬
: 可以參考以下網頁:
: http://ppt.cc/1XoB
: http://ppt.cc/YoPy
: ※ 引述《jakevin (真。假凱文)》之銘言:
: : 我想要做的只是
: : 歡迎使用本軟體 (TextView)
: : (以下為ListView)
: : 選項一(ListView)
: : 台視 (Sub Item)
: : 選項二(ListView)
: : 中視 (Sub Item)
: : 選項三(ListView)
: : 華視 (Sub Item)
: : 選項四(ListView)
: : 公視 (Sub Item)
: : 我在 Layout 是這樣佈置
: : <LinearLayout
: : <TextView android:id="@+id/textView" />
: : </LinearLayout>
: : 然後語法是用 ListActivity + SimpleAdapter
: : //新增SimpleAdapter
: : adapter = new SimpleAdapter(
: : this,
: : list,
: : android.R.layout.simple_list_item_2,
: : new String[] { "option","tv" },
: : new int[] {android.R.id.text1, android.R.id.text2} );
: : 只是在 onCreate 下
: : 加了 setContentView(R.layout.main); 就會錯誤
: : 不加就可以正常執行
: : 想請問 只是要多一個 TextView 的話
: : 怎樣做才是最好的方式呢?
: : 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.124.77.157
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):