getLayoutInflater()でテーブル行(ボタンとチェックボックス)を追加したのですが、ボタン押下のイベントが動的に追加した何行目のボタンかを取得する関数がわからないのでご教示願います。
登録したListenerからの割込みでこの処理が実行されるのは確認しています。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++MainActivity.javaの内容 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//テーブル行の動的追加処理 省略 final TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout); 省略 //全行削除 tableLayout.removeAllViews(); //タイトル表示 final TableRow tableRow0 = (TableRow) getLayoutInflater().inflate(R.layout.table_row0, null); tableLayout.addView(tableRow0, new TableLayout.LayoutParams(MP, WC)); 省略 //明細行表示 for (int ii = 0; ii < categoryNum; ii++) { 省略 // ボタン機能追加. TextView radio = (Button)tableRow.findViewById(R.id.rowradioButton); radio.setText("a"); TextView checkBox = (CheckBox)tableRow.findViewById(R.id.rowcheckBox); checkBox.setText("b"); (tableRow.findViewById(R.id.rowradioButton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { **//ボタンを押下した行数の求め方がわからない!! //Listenerからの割込みでこの処理は実行されるのですが、何行目(ii)のボタンが押下されたかを取得する関数がわかりません。 ** } }); 省略 tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC)); } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ activity_main.xmlの内容 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<?xml version="1.0" encoding="utf-8"?> 省略 <!--タイトル表示--> <TableLayout android:id="@+id/tableLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="0" > </TableLayout> 省略 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ table_row0.xmlの内容 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<?xml version="1.0" encoding="utf-8"?> <!--動的タイトル追加--> <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" > 省略 <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/textView4" android:id="@+id/button4" android:textSize="8dp" android:text="修正" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/button4" android:id="@+id/button5" android:textSize="8dp" android:text="削除" /> </TableRow> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ table_row.xml ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <?xml version="1.0" encoding="utf-8"?> <!--動的明細行追加--> <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tableRow0" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/ColorLTGRAY" > 省略 <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="1dp" android:background="@color/ColorWHITE" android:gravity="center" android:id="@+id/rowradioButton" android:checked="false" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="1dp" android:background="@color/ColorWHITE" android:gravity="center" android:id="@+id/rowcheckBox"/> </TableRow> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 前提・実現したいこと ボタン押下のイベントが動的に追加した何行目のボタンかを取得したい。 ###発生している問題・エラーメッセージ ###ソースコード ```ここに言語を入力 ###補足情報(言語/FW/ツール等のバージョンなど)`````````ここに言語を入力 ここに言語を入力
ここに言語を入力
コード
###前提・実現したいこと
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装したいのですがうまく動きません。
###発生している問題・エラーメッセージ
###ソースコード
ここにご自身が実行したソースコードを書いてください
###補足情報(言語/FW/ツール等のバージョンなど)```- ここに言語を入力
コード
ソースコードを書く際には、
```ここに言語を入力
コード
```
にいれて投稿しましょう。 コードがよめないです。
回答1件
あなたの回答
tips
プレビュー