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

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

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

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

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

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

0回答

1370閲覧

EditTextのtextを複数取得

prog.que

総合スコア2

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

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

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2021/03/13 04:59

簡単な単語登録アプリを作成しています

登録の際に、+ボタンを押すと追加でEditTextが表示され入力できます。
ですが、テキストを取得しようとすると複数あるうちの一つ目のEditTextのテキストしか取得できません。

一気にすべて取得してDBい登録したいのですが、うまく取得できていない状況です

どうすればすべてのEditTextのテキストを取得することできますか?

kotlin

1package com.application.englishword 2 3import android.os.Bundle 4import android.view.View.inflate 5import android.widget.Button 6import android.widget.EditText 7import android.widget.LinearLayout 8import androidx.appcompat.app.AppCompatActivity 9 10class AddActivity : AppCompatActivity() { 11 override fun onCreate(savedInstanceState: Bundle?) { 12 super.onCreate(savedInstanceState) 13 setContentView(R.layout.add_activity) 14 15 val linearLayout = findViewById<LinearLayout>(R.id.addEditArea) 16 val pluceButton = findViewById<Button>(R.id.pluceButton) 17 18 19 pluceButton.setOnClickListener { 20 val inflate = inflate(this,R.layout.edit_form_activity,null) 21 linearLayout.addView(inflate) 22 } 23 24 25 } 26}

XML

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent"> 8 9 <Button 10 android:id="@+id/okButton" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:text="@string/ok" 14 app:layout_constraintEnd_toEndOf="parent" 15 app:layout_constraintTop_toTopOf="parent" /> 16 17 18 <ScrollView 19 android:layout_width="match_parent" 20 android:layout_height="0dp" 21 app:layout_constraintBottom_toTopOf="@+id/pluceButton" 22 app:layout_constraintEnd_toEndOf="parent" 23 app:layout_constraintHorizontal_bias="0.0" 24 app:layout_constraintStart_toStartOf="parent" 25 app:layout_constraintTop_toBottomOf="@+id/okButton" 26 app:layout_constraintVertical_bias="0.0"> 27 28 <LinearLayout 29 android:id="@+id/addEditArea" 30 android:layout_width="match_parent" 31 android:layout_height="wrap_content" 32 android:layout_marginTop="20dp" 33 android:orientation="vertical" /> 34 </ScrollView> 35 36 <Button 37 android:id="@+id/pluceButton" 38 android:layout_width="50dp" 39 android:layout_height="50dp" 40 android:text="@string/pluce" 41 android:layout_marginEnd="10dp" 42 android:fontFamily="sans-serif-black" 43 app:layout_constraintBottom_toBottomOf="parent" 44 app:layout_constraintEnd_toEndOf="parent" /> 45</androidx.constraintlayout.widget.ConstraintLayout>

XML

1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" 5 xmlns:android="http://schemas.android.com/apk/res/android"> 6 <EditText 7 android:layout_width="150dp" 8 android:layout_height="wrap_content" 9 android:hint="@string/enEditHint" 10 android:gravity="center" 11 android:layout_marginLeft="30dp" 12 android:layout_alignParentLeft="true"/> 13 <EditText 14 android:layout_width="150dp" 15 android:layout_height="wrap_content" 16 android:hint="@string/jaEditHint" 17 android:gravity="center" 18 android:layout_marginRight="30dp" 19 android:layout_alignParentRight="true"/> 20</RelativeLayout>

イメージ説明

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

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

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

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

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

hoshi-takanori

2021/03/13 07:36

inflate した view をリストか何かで管理する必要があるでしょうね。
prog.que

2021/03/13 09:31

viewをリストで管理とはどういうことでしょうか?
hoshi-takanori

2021/03/13 09:53

ArrayList<View> を作って、inflate したものを add する的な…。というか、そもそも EditText に id がないようですが、EditText からのテキストの取得はどうやってますか?
prog.que

2021/03/13 10:33

プラスボタンを押したときに動的にEditTextを作成しているので、setidで設定する予定です
hoshi-takanori

2021/03/13 10:39

setid するにしても EditText を取得する必要があるし、set した id を覚えておく必要があるのでは。 (そもそも setid する必要があるとも思いませんけど…。)
prog.que

2021/03/13 10:53

setidで識別しないと複数のedittextを取得できないと思いますが、どうでしょうか?
hoshi-takanori

2021/03/13 10:55

Activity の findViewById はそうですが、View の findViewById を使えばその view の配下にあるものだけを対象にできるので、inflate した直後に英語と日本語の EditText をそれぞれ取得して、リストに追加すれば良いのでは。
prog.que

2021/03/13 11:00 編集

ただ、edittextからtextを取得するにはidが必要なのではないのですか?
hoshi-takanori

2021/03/13 11:01

はい。なので、edit_form_activity.xml の各 EditText に固定の id を指定して、コードから setid する必要はないという話をしています。
prog.que

2021/03/13 11:09

なるほど これで添付した画像のように複数あっても識別できると言うことですね
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問