2
我爲我的應用程序使用以下main.xml。ListView將不會再顯示
<?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="fill_parent"
android:id="@+id/toplinear">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linear">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/previous"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/next"
android:layout_toRightOf="@id/previous"
android:layout_weight="1"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/android:list"
android:layout_weight="10"
/>
</LinearLayout>
我想要在頂部,上一個和下一個按鈕,以及我的列表視圖與下面的自定義適配器。幾天前,我只有我的ListView顯示,檢查按鈕。現在我似乎被卡在另一邊,在我的按鈕的時候,我的列表視圖不顯示。
我的活動在ListActivity上進行擴展,並使用此代碼將其填充到customadapter中。
ListView lv = getListView();
lv.setAdapter(new MyCustomAdapter(this, R.layout.custom_list, nameResults));
public class MyCustomAdapter extends ArrayAdapter<String> {
private String[] nameResults;
private Context context;
public MyCustomAdapter(Context context, int textViewResourceId,
String[] names) {
super(context, textViewResourceId, names);
this.context = context;
nameResults = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.custom_list, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.Name);
label.setText(nameResults[position]);
TextView descr = (TextView) row.findViewById(R.id.Description);
descr.setText(linkedResults.get(nameResults[position]));
return row;
}
}
我試過使用「lv.addHeaderView(previous);」但是這隻會給我關於LayoutParams的模糊的ClassCastExceptions。
我想我的問題目前在我的main.xml中,因爲它的Eclipse中的佈局選項卡不會顯示ListView。它知道它在大綱標籤中顯示的位置,但是當我選擇它時,可視化表示不會給它一個紅色輪廓。
爲了完整起見,我custom_list(又名行)佈局的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Name"
android:textColor="#000000"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Description"
android:textColor="#000000"
/>
</LinearLayout>
這似乎已經修復它,謝謝!介意給我一個這個問題upvote?需要更多的代表,所以我可以upvote你以及! :D – Rvthof 2010-07-03 23:11:08
不客氣 - 投票完成。 – xil3 2010-07-03 23:58:47