我有一個活動,我試圖展示一些簡單的消息,然後列出項目。據我所知,我需要兩個視圖:一個用於簡單佈局,一個用於將由適配器處理的項目列表。Android - 無法合併視圖
這裏是我的代碼:
ArrayAdapter<SolutionTopic> adapter;
ArrayList<SolutionTopic> problems = new ArrayList <SolutionTopic>();
/**當第一次創建活動時調用。 */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Load your layout
setContentView(R.layout.solution);
SolutionTopic s = new SolutionTopic();
s.setSolutionTopicName("Hello");
problems.add(s);
adapter = new ArrayAdapter<SolutionTopic>(this, R.layout.solution_topic_list,
R.id.label, problems);
TextView solution_title = (TextView) findViewById(R.id.solution_title);
TextView solution_description = (TextView) findViewById(R.id.solution_description);
setListAdapter (adapter);
}
這裏是solution.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/solution_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Label1"
/>
<TextView
android:id="@+id/solution_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Label2"
/>
</LinearLayout>
這裏是solution_topic_list.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
什麼我不知道是如何得到這些兩個一起渲染。理想情況下,我想要做的是先顯示TextView消息,然後顯示項目列表。
任何想法我可以做到這一點?
謝謝!
您的Activity是ListActivity的子類嗎?當你開始你的活動時,你目前看到什麼? – louielouie 2012-03-20 04:31:03