この単純なアプリの目標は、ユーザーがリスト内の 1 つのアイテムをクリックすると、クリックされたオブジェクトに関連付けられたアイテムを含む別のリストに移動するように、1 対多の関係を持つことです。簡単な例: トップ リストには、イディオム、句動詞の 2 つの項目があります。ユーザーがイディオムをクリックするとイディオムのリストが表示され、ユーザーが句動詞をクリックすると句動詞のリストが表示されます。イディオムのリストに到達した後、イディオムを選択すると、定義と例を表示するテキスト ビューに移動します。現在、トピック リスト (イディオムと句動詞) は ListView に適切に表示されますが、そのうちの 1 つをクリックするとアプリが終了し、多くのエラーが発生します。これは (E/AndroidRuntime(276): 原因: android. content.res.Resources$NotFoundException: 文字列配列リソース ID #0x0) クリックしたリスト項目に関連付けられた 1 対多を取得するにはどうすればよいですか? 私の意図は正しいですか?
<string-array name="topics">
<item>Idioms</item>
<item>Phrasal Verbs</item>
<string-array name="idioms">
<item>Cash Chow</item>
<item>In the Black</item>
</string-array>
<string-array name="pverbs">
<item>Back up</item>
<item>Back down</item>
</string-array>
メインのアクティビティ ファイルは次のようになり、エミュレータで正しく表示されています。
public class TestActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] topics = getResources().getStringArray(R.array.topics);
setListAdapter(new ArrayAdapter<String>(this, R.layout.topic_list, topics));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent i = new Intent(TestActivity.this, Sublist.class);
i.putExtra("position", position);
startActivity(i);
私が作成した 2 番目のクラスは Sublist と呼ばれ、これがその中にあるコードです。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
int arrayB = extras.getInt("position");
String[] subtopics = getResources().getStringArray(arrayB);
setListAdapter(new ArrayAdapter<String>(this, R.layout.topic_list, subtopics));
ListView lv = getListView();
lv.setTextFilterEnabled(true);