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

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

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

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

Android Studio

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

Kotlin

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

Q&A

0回答

750閲覧

ListViewのレイアウトに含まれる、画面部品Spinnerのドロップリストの内容を、各行ごとに変更して表示したい

qishihuang

総合スコア2

Android

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

Android Studio

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

Kotlin

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

0グッド

0クリップ

投稿2020/10/17 15:31

発生している問題・エラーメッセージ

リストビュー各行のレイアウトファイルを作成し、アダプターにカスタマイズしました。そこに含まれる画面部品Spinnerの入力内容を各行ごとに変更したいのですが、やり方がさっぱりわかりません。もし知ってる方がいれば、教えていただきたいです。

該当のソースコード

kotlin

1アクティビティに渡すためのレイアウトファイル 2<?xml version="1.0" encoding="utf-8"?> 3<LinearLayout 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 android:orientation="vertical" 9 android:id="@+id/linear"> 10 11 <ListView 12 android:id="@+id/listview" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" /> 15 16</LinearLayout> 17

kotlin

1アクティビティ 2class MainActivity : AppCompatActivity() { 3 4 override fun onCreate(savedInstanceState: Bundle?) { 5 super.onCreate(savedInstanceState) 6 setContentView(R.layout.activity_main) 7 8    //リストビューのTextView用 9 val dog = Animal("体重") 10 val cat = Animal("身長") 11 val elephant = Animal("年齢") 12 val mAnimalList = arrayListOf(dog, cat, elephant) 13 14 val name = findViewById<TextView>(R.id.reagent_name) 15 val listview = findViewById<ListView>(R.id.listview) 16 val adapter = CustomAdapter(this, mAnimalList) 17 18 listview.adapter=adapter 19 } 20}

kotlin

1ListView用のカスタムAdapter 2class CustomAdapter(context: Context, var mAnimalList: List<Animal>) : ArrayAdapter<Animal>(context, 0, mAnimalList) { 3 4 private val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater 5 6 override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { 7 // Animalの取得 8 val animal = mAnimalList[position] 9 10 // レイアウトの設定 11 var view = convertView 12 if (convertView == null) { 13 view = layoutInflater.inflate(R.layout.row, parent, false) 14 } 15 16 // 各Viewの設定 17 val name = view?.findViewById<TextView>(R.id.reagent_name) 18 name?.text = animal.name 19 20 return view!! 21 } 22}

kotlin

1dataクラス 2data class Animal ( 3 val name: String 4)

kotlin

1strings.xml(身長用の単位しか用意していません) 2<resources> 3 <string name="app_name">D</string> 4 <string-array name="gram"> 5 <item>g</item> 6 <item>kg</item> 7 </string-array> 8</resources>

kotlin

1ListView各行のレイアウトファイル 2<?xml version="1.0" encoding="utf-8"?> 3<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="horizontal"> 7 8 <TextView 9 android:id="@+id/reagent_name" 10 android:layout_width="70dp" 11 android:layout_height="wrap_content" 12 android:layout_marginLeft="20dp" 13 android:text="" /> 14 15 <EditText 16 android:id="@+id/volume" 17 android:layout_width="80dp" 18 android:layout_height="wrap_content" 19 android:layout_marginLeft="85dp" 20 android:inputType="number" /> 21 22 <Spinner 23 android:id="@+id/spinner" 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:layout_marginLeft="10dp" 27 android:entries="@array/gram" /> 28 29</LinearLayout>

補足情報(FW/ツールのバージョンなど)

Android Studio 3.5.3

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問