私は自分のアプリに次のmain.xmlを使用しています。
<?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>
上部に2つのボタン、前と次、およびその下にカスタムアダプタを含むリストビューを配置したいと思います。数日前、私はListViewだけを表示し、ボタンを確認しました。今、私は反対側で立ち往生しているようです。ボタンが表示されているのにリストビューが表示されません。
私のアクティビティはListActivityを拡張し、このコードを使用してカスタムアダプターを入力します。
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を与えただけです。
Eclipseの[レイアウト]タブにもListViewが表示されないため、現在、私の問題はmain.xmlにあると思います。[アウトライン]タブに表示されるので、そこにあることがわかりますが、選択したときに視覚的な表現で赤いアウトラインが表示されません。
完全を期すために、私の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>