我試圖把ListView
和TextView
放在相同的佈局,我設法這樣做,但執行應用程序時,我得到了一些錯誤。 下面是XML代碼 ` 如何把ListView和TextView放在android的相同佈局中?
<ListView
android:id="@+id/lvCourses"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="40" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="60"
android:orientation="vertical" >
<TextView
android:id="@+id/tvHOD"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="Output here" />
</LinearLayout>
</LinearLayout>
這裏是Java代碼
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.teacher);
Courses = (ListView) findViewById(R.id.lvCourses);
Output = (TextView) findViewById(R.id.tvHOD);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, Names);
Courses.setAdapter(adapter);
Courses.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Output.setText(HOD[arg2]);
}
logcat中說,錯誤是在的onCreate功能,但在看見碼我無法理解一切看起來很好。 需要幫助。
你應該張貼您的日誌另存爲文本不作爲截圖好友 –
請參考您問題頂部鏈接的副本。所需的ID具有非常特定的格式。 –