私はプログラマーではないので、自分の仕事に役立つアプリを作るのが好きなので、適切なプログラミングについてはよくわかりません。そうは言っても、これは私が反対していることです。1から100までの数値を入力すると、アプリはその数の行を含むスクロール可能なテーブルレイアウトを作成します。各行には、textview、edittext、および別のtextviewがあります。ここに私のコードがあります。
TableLayout tL = (TableLayout)findViewById(R.id.tableLayout1);
// creates all the fields
for(int i = 1; i <= numOfInjWells; i++) {
TableRow tR = new TableRow(this);
// creates the textView
TextView tV1 = new TextView(this);
tV1.setText(" " + i + ": ");
// add edit text
EditText eT = new EditText(this);
eT.setText("Meter Reading");
eT.setInputType(InputType.TYPE_CLASS_NUMBER);
TextView tV2 = new TextView(this);
tV2.setText("");
// add the TextView and the editText to the new TableRow
tR.addView(tV1);
tR.addView(eT);
tR.addView(tV2);
// add the TableRow to the TableLayout
tL.addView(tR,new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
} // end for statement
したがって、1行目のエディットテキスト(eT)に数値を入力するときに、その数値とデータベースに保存した数値との差を計算します(データベースから必要な特定の数値を取得する方法はすでに知っています)。次に、1行目のtextview tV2を変更して、ボタンをクリックしなくても違いが表示されるようにします。私が遭遇している問題は、すべてのエディットテキストとテキストビューが同じ名前eTまたはtV2を持っているため、1行目のエディットテキスト(eT)をテキストビュー(tV2)に関連付ける方法です。
ご協力いただきありがとうございます。コーディングについてよく知らないことをお詫び申し上げます。
編集:私は追加することを考えました
eT.setId(i);
tV2.setId(i);
しかし、それを計算に使用する方法がわかりません。