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 は何処にあるのでしょうか。
アドバイスよろしくお願いします。
No.1ベストアンサー
- 回答日時:
ふつうはlayout.xmlファイルで、画面オブジェクトを定義していなければ使えないよ。
text3をレイアウトファイルにも追加済みか、スペルミスがないか要確認。ありがとうございます。
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言語の 外部変数 のようなものは無いのでしょうか?
それがあれば、簡単なのですが、、、
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
エクセルで最後の文字だけ置き...
-
エラー 1068 (42000): 複数の主...
-
副問合せの書き方について
-
エクセルの関数について教えて...
-
Updateの複数テーブル条件時のL...
-
WordpressのContact form 7でzi...
-
Access パラメータクエリをcsv...
-
【MySQL】auto_incrementの値を...
-
NOT INをNOT EXISTSで書き直したい
-
inner joinをすると数がおかし...
-
VBAでボタンをクリックする方法...
-
MySQLのint型で001と表示する方...
-
一つ前のレコードの値と減算し...
-
VIEWの元のテーブルのindexって...
-
SQLサーバから、項目の属性(型...
-
複数JOINしているとCOUNTが正し...
-
期間の重複を調べるSQL文につい...
-
ある条件の最大値+1を初番する...
-
カラム名でseqとidではどちらが...
-
select文のwhere句に配列を入れ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
エクセルで最後の文字だけ置き...
-
エクセルの関数について教えて...
-
VIEWの元のテーブルのindexって...
-
副問合せの書き方について
-
select文のwhere句に配列を入れ...
-
マイクラPC版のコマンドで効率...
-
SQLサーバから、項目の属性(型...
-
エラー 1068 (42000): 複数の主...
-
[MySQL] 3つのテーブルの結合で...
-
Access パラメータクエリをcsv...
-
SQLにて特定の文字を除いた検索...
-
SQL Left Join で重複を排除す...
-
ストアドのエラーについて
-
Unionした最後にGROUP BYを追加...
-
バインド変数について
-
PL/SQLの変数について
-
sqlで、600行あるテーブルを100...
-
WordpressのContact form 7でzi...
-
selectした大量データをinsert...
-
inner joinをすると数がおかし...
おすすめ情報