AndrodStudioで複数のEditTextを使いたい
EditTextの使い方を教えて下さい 初心者ですよろしくお願いします。
5個又は6個のEditTextを配置してEditTextに入力した値をリアルタイムに個々のTextViewに表示したいのですが?
例えば
EditText1に入力した値をTextView1に表示
EditText2に入力した値をTextView2に表示
EditText3に入力した値をTextView3に表示
EditText5に入力した値をTextView4に表示
EditText5に入力した値をTextView5に表示
EditText6に入力した値をTextView6に表示と、
■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
AndroidStudio
1public class MainActivity extends Activity implements TextWatcher { 2 3@Override 4 public void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 8 EditText edittext = (EditText)findViewById(R.id.edittext); 9 edittext.addTextChangedListener(this); //追加 10 } 11 12 /*--- 追加 ---*/ 13 14 @Override 15 public void beforeTextChanged(CharSequence s, int start, int count,int after) { 16 //操作前のEtidTextの状態を取得する 17 } 18 19 @Override 20 public void onTextChanged(CharSequence s, int start, int before, int count) { 21 //操作中のEtidTextの状態を取得する 22 } 23 24 @Override 25 public void afterTextChanged(Editable s) { 26 //操作後のEtidTextの状態を取得する 27 28 /*--- 取得例(EditTextの更新内容をTextViewに反映) ---*/ 29 TextView textView = (TextView)findViewById(R.id.textview); 30 textView.setText(s.toString()); 31 /*--- 取得例 ---*/ 32 33 } 34 35 /*--- 追加 ---*/ 36 37} 38 39 40 41### 試したこと 42 43リアルタイムにTextViewに表示されますが 44複数の EditTextとTextViewを使うにはどうすればいいのでしょうか? 45 46### 補足情報(androidStudio2.3) 47 48ここにより詳細な情報を記載してください。
コードの範囲は```の行で上下をサンドイッチするようにしてください。また、言語のところにAndroidStudioと記されていますが、AndroidStudioは言語ではなく開発環境(IDE)です。この場合はjavaと記述されるべきです。
ご指摘有難うございます。次回から気を付けます。
質問は自分で編集できますから、今からでも修正できますよ。
activity_main.xml をご質問に 追記 願えますでしょうか.
その際は keicha_hrs さんご指摘のように ``` でサンドイッチして, 言語として xml とお願い致します.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ith.ith_edit.MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="92dp"
android:layout_height="41dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.072" />
<EditText
android:id="@+id/editText2"
android:layout_width="92dp"
android:layout_height="41dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberDecimal"
android:selectAllOnFocus="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.22" />
<TextView
android:id="@+id/textView"
android:layout_width="79dp"
android:layout_height="29dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintVertical_bias="0.354" />
<TextView
android:id="@+id/textView2"
android:layout_width="79dp"
android:layout_height="29dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.467"
app:layout_constraintHorizontal_bias="0.501" />
</android.support.constraint.ConstraintLayout>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
とりあえずedittext 2個、textview 2個です。宜しくお願いします
追記出来なかったようですね…
ご提示されているコードと頂いたXMLの組み合わせではコンパイルエラーになりますが, 合っていますでしょうか.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
/*--- 取得例(EditTextの更新内容をTextViewに反映) ---*/
TextView textView = (TextView)findViewById(R.id.textview);
textView.setText(s.toString());
/*--- 取得例 ---*/
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
1個目のedittextの値を1個目textviewに値を表示できます。
teratailの使い方が不慣れなご迷惑をおかけします
回答2件
あなたの回答
tips
プレビュー