プロが教える店舗&オフィスのセキュリティ対策術

androidアプリ開発
を読みながら、作業しています。 ( 184ページ )

サンプルのコード
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this,
g_list,
android.R.layout.simple_expandable_list_item_1,
new String[] { "group_title"},
new int[]{android.R.id.text1 },
c_list,
android.R.layout.simple_expandable_list_item_2,
new String[] {"child_title", "child_text" },
new int[] { android.R.id.text1, android.R.id.text2 }
);
elv.setAdapter(adapter);

elv.setOnChildClickListener(
new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1);
Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show();
return false;
}
}

は、動くのですが、欲張って

SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this,
g_list,
android.R.layout.simple_expandable_list_item_1,
new String[] { "group_title"},
new int[]{android.R.id.text1 },
c_list,
android.R.layout.simple_expandable_list_item_2,
new String[] {"child_title", "child_text" },
new int[] { android.R.id.text2, android.R.id.text3 }
);
elv.setAdapter(adapter);

elv.setOnChildClickListener(
new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1);
Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show();
TextView txt2 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text2);
Toast.makeText(AddrListShowActivity.this, txt2.getText(), Toast.LENGTH_LONG).show();
TextView txt3 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text3);
Toast.makeText(AddrListShowActivity.this, txt3.getText(), Toast.LENGTH_LONG).show();

return false;
}
}

とすると、android.R.id.text3  が原因で動きません。

そもそも、android.R.id.text1 の  text1 は何処にあるのでしょうか。

アドバイスよろしくお願いします。
 

A 回答 (1件)

ふつうはlayout.xmlファイルで、画面オブジェクトを定義していなければ使えないよ。

text3をレイアウトファイルにも追加済みか、スペルミスがないか要確認。
    • good
    • 0
この回答へのお礼

ありがとうございます。

res - layout の所には、 antivity_main.xml だけがあって
その中身は、以下のようになっています。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ExpandableListView
android:id="@+id/elv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ExpandableListView>
</RelativeLayout>

よく見ても、無いのです。

amdroid の プログラムでは、C言語の 外部変数 のようなものは無いのでしょうか?
それがあれば、簡単なのですが、、、

お礼日時:2014/12/01 07:17

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!