質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

5048閲覧

getLayoutInflater()でテーブル行(ボタンとチェックボックス)を追加した時のイベント発生行取得方法

SumioShimizu

総合スコア16

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2015/12/09 03:23

編集2015/12/09 03:54

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/ツール等のバージョンなど)```- ここに言語を入力
コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

liguofeng29

2015/12/09 03:26

ソースコードを書く際には、 ```ここに言語を入力 コード ``` にいれて投稿しましょう。 コードがよめないです。
guest

回答1

0

ベストアンサー

View#setTagを使い、Viewに行数を渡します。
onClickの引数にあるvでView#getTagを行うと行数が取得できます。

投稿2015/12/09 03:42

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

SumioShimizu

2015/12/09 05:08

行数の取得が出来ました。ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問