そのため、同じレイアウトのボタンの下に ListView を配置しようとしています。基本的に、ListView オプションを選択すると、選択したオプションごとにボタンの反応が異なります。問題は、強制的に閉じられていることであり、ListView の設定に問題があるようです。
<?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="@drawable/background"
>
<Button
android:background="@drawable/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:id="@+id/button"/>
<ListView
android:listSelector="#990000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:id="@+id/listview"
/>
</LinearLayout>
コード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView) findViewById(R.id.listview);
ArrayList<String> list = new ArrayList<String>();
soundsList.add("one");
soundsList.add("two");
soundsList.add("three");
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
lv.setAdapter(arrayAdapter);
Logcat の読み取り値は次のとおりです。
08-23 10:21:23.735: ERROR/AndroidRuntime(588): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
私はArrayAdapterでそれが言うことを正確に試しました...(android.R.id.list。ListActivityを拡張するなど、他にも多くのことを試しましたが、何を試しても同様のLogcat応答が得られるようです.
私が達成しようとしていることをやってのけるより良い方法はありますか? ListView の上にあるボタンをすべて同じ main.xml に配置したい。
前もって感謝します。
編集:
私もこのコードを試しました。現在はコメントアウトされていますが、元々やってみたものでした。
setListAdapter(new ArrayAdapter<String>(this, android.R.id.list,LIST));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
LIST は文字列配列です。上記のコードからの Logcat の出力は、前と同じでした。