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

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

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

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Java

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

Android

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

Android Studio

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

Kotlin

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

Q&A

解決済

2回答

1472閲覧

ListView が表示されない

退会済みユーザー

退会済みユーザー

総合スコア0

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Java

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

Android

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

Android Studio

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

Kotlin

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

0グッド

0クリップ

投稿2020/09/11 23:21

スクロールするリストビューを作りたいです。
コンパイルエラー、実行エラーは出なくなるまで直しました。
しかし、タイトルだけが表示されてリストビューが表示されません。
Kotlin のソースコードの問題というより、レイアウトのxmlが間違ってるような気がします。
どこが間違えてるのか教えて下さい。
宜しくお願い致します。

DisplayActivity.kt package com.haikudojo import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.ListView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.snackbar.Snackbar class DisplayActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_display) setSupportActionBar(findViewById(R.id.toolbar)) findViewById<CollapsingToolbarLayout>(R.id.toolbar_layout).title = title findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show() } // サンプル用のデータを準備 val dataList: MutableList<Data> = ArrayList() // サンプル用のデータを詰め込む for (i in 1..100) { val data = Data( i.toString(), "古池や蛙飛び込む水の音", "松尾芭蕉", "20段") dataList.add(data) } // リストにサンプル用のデータを受け渡す val arrayAdapter = ListAdapter(this, dataList) Log.d("DisplayActivity", "arrayAdapter : " + arrayAdapter.toString()) //setListAdapter(adapter) Log.d("DisplayActivity", "R.id.listView : " + R.id.listView.toString()) val listView: ListView = findViewById(R.id.listView) Log.d("DisplayActivity", "listView : " + listView.toString()) listView.setAdapter(arrayAdapter) } } // データ格納用クラス class Data { var num: String? = null //No. var haiku: String? = null //俳句 var name: String? = null //苗字 俳号 var haikuClass: String? = null //級 // constructor(uid: String?, kamiku: String?, chuku: String?, shimoku: String?, time: LocalDateTime?) { constructor(num: String, haiku: String, name: String, haikuClass: String) { this.num = num this.haiku = haiku this.name = name this.haikuClass = haikuClass } constructor() {} } // リスト表示制御用クラス class ListAdapter(context: Context, objects: MutableList<Data>) : BaseAdapter() { var context: Context var layoutInflater: LayoutInflater? = null; var haikuList: MutableList<Data> = objects init { this.context = context layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } override fun getCount(): Int { return haikuList.size } override fun getItem(position: Int): Data? { return haikuList[position] } override fun getItemId(position: Int) = position.toLong() @SuppressLint("ViewHolder") override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { val myview: View? val layoutInflater: LayoutInflater = LayoutInflater.from(context); //if (view == null) { // view = layoutInflater.inflate(R.layout.raw, parent, false) //} myview = layoutInflater.inflate(R.layout.raw, parent, false) (myview.findViewById(R.id.raw1) as? TextView)?.setText(haikuList[position].num) (myview.findViewById(R.id.raw2) as? TextView)?.setText(haikuList[position].haiku) (myview.findViewById(R.id.raw3) as? TextView)?.setText(haikuList[position].name) (myview.findViewById(R.id.raw4) as? TextView)?.setText(haikuList[position].haikuClass) return myview } }
layout/activity_display.xml <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout 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" android:fitsSystemWindows="true" tools:context=".DisplayActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/app_bar" android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" app:toolbarId="@+id/toolbar" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> <include layout="@layout/content_scrolling" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" app:layout_anchor="@id/app_bar" app:layout_anchorGravity="bottom|end" app:srcCompat="@android:drawable/ic_dialog_email" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
layout/content_scrolling.xml <?xml version="1.0" encoding="utf-8"?> <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_display" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DisplayActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="1dp" android:layout_weight="1" /> </LinearLayout> </androidx.core.widget.NestedScrollView>
layout/raw.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/raw1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:singleLine="true" android:layout_marginRight="@dimen/text_margin" android:padding="@dimen/text_margin" android:textSize="@dimen/text_margin" /> <TextView android:id="@+id/raw2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" android:singleLine="true" android:layout_marginRight="@dimen/text_margin" android:padding="@dimen/text_margin" android:textSize="@dimen/text_margin" /> <TextView android:id="@+id/raw3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" android:singleLine="true" android:layout_marginRight="@dimen/text_margin" android:padding="@dimen/text_margin" android:textSize="@dimen/text_margin" /> <TextView android:id="@+id/raw4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" android:singleLine="true" android:layout_marginRight="@dimen/text_margin" android:padding="@dimen/text_margin" android:textSize="@dimen/text_margin" /> </LinearLayout>

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

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

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

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

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

guest

回答2

0

ベストアンサー

有料のサービスを利用して解決しました。

投稿2020/09/25 01:53

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

0

  • ListView の高さは wrap_content
    • 親の高さも決まっていないので計算できなそう
  • notifyDataSetChanged する必要がある?

かと思いました。

投稿2020/09/12 02:01

unhappychoice

総合スコア1531

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

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

退会済みユーザー

退会済みユーザー

2020/09/12 02:21

ありがとうございます。 調べてみます。
退会済みユーザー

退会済みユーザー

2020/09/25 01:52

有料のサービスを利用して解決しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問