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

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

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

RealmとはSQLiteやCore Dataに代わるモバイルデータベースです。iOSとAndroidの両方でサポートされています。

Android Studio

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

Kotlin

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

Q&A

0回答

310閲覧

複数のTextViewをListViewにまとめたい

asdfhorse

総合スコア17

Realm

RealmとはSQLiteやCore Dataに代わるモバイルデータベースです。iOSとAndroidの両方でサポートされています。

Android Studio

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

Kotlin

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

0グッド

0クリップ

投稿2018/12/14 04:46

家計簿アプリを作成しています。
月別のジャンル支出を一覧表示させたいと考えています。
月別のジャンル支出の値を取ってきて、TextViewに表示させることはできているのですが、それをListViewでまとめて表示させたいと考えています。
どなたかご教授お願いします。

koltin

1package com.example.tamayamaryo.recipebook_sotuken 2 3class MainActivity: FragmentActivity(), DatePick.Callback { 4 private lateinit var realm: Realm 5 6 7 private fun initRealm() { 8 val realmConfiguration = RealmConfiguration.Builder() 9 .deleteRealmIfMigrationNeeded() 10 .schemaVersion(0) 11 .build() 12 realm = Realm.getInstance(realmConfiguration) 13 14 } 15 16 override fun onCreate(savedInstanceState: Bundle?) { 17 super.onCreate(savedInstanceState) 18 setContentView(R.layout.activity_main) 19 20 val config = RealmConfiguration.Builder().deleteRealmIfMigrationNeeded().build() 21 22 Realm.setDefaultConfiguration(config) 23 24 realm = Realm.getDefaultInstance() 25 26 27 28 val kakeibo_navi: BottomNavigationItemView = findViewById(R.id.navigation_kakeibo) 29 val resito_navi: BottomNavigationItemView = findViewById(R.id.navigation_resito) 30 val buylist_navi: BottomNavigationItemView = findViewById(R.id.navigation_buylist) 31 val recipe_navi: BottomNavigationItemView = findViewById(R.id.navigation_analysis) 32 kakeibo_navi.setOnClickListener { 33 val intent = Intent(this, kakeiboActivity::class.java) 34 startActivity(intent) 35 } 36 buylist_navi.setOnClickListener { 37 val intent = Intent(this, buylistActivity::class.java) 38 startActivity(intent) 39 } 40 resito_navi.setOnClickListener { 41 val intent = Intent(this, resitoActivity::class.java) 42 43 startActivity(intent) 44 } 45 recipe_navi.setOnClickListener { 46 val intent = Intent(this, MainActivity::class.java) 47 startActivity(intent) 48 } 49 50 } 51 override fun onDestroy() { 52 super.onDestroy() 53 realm.close() 54 } 55 override fun onDatePicked(year: Int,monthOfYear: Int, dayOfMonth: Int) { 56 val str = String.format(Locale.US, "%d/%d", year, monthOfYear+1 , dayOfMonth) 57 datesort.text = str 58 59 var kakeiboOfMonth = realm.where<Kakeibo>() 60 .beginsWith("date", "${year}/${monthOfYear+1}/") 61 .findAll() 62 kakeiboOfMonth = kakeiboOfMonth.sort("date") 63 64 var sumSyunyu = kakeiboOfMonth.where().equalTo("shushi", "収入").findAll().sum("money").toString() 65 var sumSisyutsu = kakeiboOfMonth.where().equalTo("shushi", "支出").findAll().sum("money").toString() 66 sumsShunyu.text = sumSyunyu 67 sumsiSishutu.text = sumSisyutsu 68 var shushi : Int = Integer.parseInt(sumSyunyu) - Integer.parseInt(sumSisyutsu) 69 shuushi.text = shushi.toString() 70 71 //ジャンルごとの支出 72 var dayvalue = kakeiboOfMonth.where() 73 .equalTo("genre", "日用品") 74 .findAll().sum("money").toString() 75 dayv.text = dayvalue 76 77 var foodvalue = kakeiboOfMonth.where() 78 .equalTo("genre", "食費") 79 .findAll().sum("money").toString() 80 foodv.text = foodvalue 81 82// var elecvalue = kakeiboOfMonth.where() 83// .equalTo("genre", "水道光熱費") 84// .findAll().sum("money").toString() 85// electricalv.text = elecvalue 86// var healthvalue = kakeiboOfMonth.where() 87// .equalTo("genre", "医療費") 88// .findAll().sum("money").toString() 89// healthv.text = healthvalue 90// 91// var beatyvalue = kakeiboOfMonth.where() 92// .equalTo("genre", "美容・衣服") 93// .findAll().sum("money").toString() 94// beautyv.text = beatyvalue 95// 96// var mobilevalue = kakeiboOfMonth.where() 97// .equalTo("genre", "通信料") 98// .findAll().sum("money").toString() 99// mobilev.text = mobilevalue 100// 101// var detvalue = kakeiboOfMonth.where() 102// .equalTo("genre", "交際費") 103// .findAll().sum("money").toString() 104// detv.text = detvalue 105// 106// var drivevalue = kakeiboOfMonth.where() 107// .equalTo("genre", "交通費") 108// .findAll().sum("money").toString() 109// drivev.text = drivevalue 110// 111// var housevalue = kakeiboOfMonth.where() 112// .equalTo("genre", "住まい") 113// .findAll().sum("money").toString() 114// housev.text = housevalue 115// 116// var hobbyvalue = kakeiboOfMonth.where() 117// .equalTo("genre", "娯楽") 118// .findAll().sum("money").toString() 119// hobbyv.text = hobbyvalue 120// 121// var othervalue = kakeiboOfMonth.where() 122// .equalTo("genre", "その他") 123// .findAll().sum("money").toString() 124// otherv.text = othervalue 125 126 127 } 128 129 override fun onAttachFragment(fragment : Fragment) { 130 if(fragment is DatePick) { 131 fragment.callback = this 132 } 133 } 134 fun showDatePickerDialog(v: View) { 135 val newFragment = DatePick() 136 newFragment.show(supportFragmentManager, "datePicker") 137 } 138 139}

xml

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.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:id="@+id/container" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 tools:context=".MainActivity"> 10 <TextView 11 android:id="@+id/analysis" 12 android:text="@string/analysis" 13 android:textSize="25dp" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 app:layout_constraintLeft_toLeftOf="parent" 17 app:layout_constraintTop_toTopOf="parent" 18 android:layout_marginLeft="268dp" android:layout_marginTop="16dp"/> 19 <TextView 20 android:id="@+id/datesort" 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" 23 android:layout_marginLeft="112dp" 24 android:text="@string/title_nengetu" 25 android:textSize="25dp" 26 android:onClick="showDatePickerDialog" 27 app:layout_constraintLeft_toLeftOf="parent" 28 app:layout_constraintTop_toTopOf="parent" 29 /> 30 <TextView 31 android:id="@+id/shunyuuText" 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:text="@string/shunyuu" 35 android:textSize="20dp" 36 app:layout_constraintLeft_toLeftOf="parent" 37 app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="360dp" 38 android:layout_marginLeft="16dp"/> 39 <TextView 40 android:id="@+id/sishutuText" 41 android:layout_width="wrap_content" 42 android:layout_height="wrap_content" 43 android:text="@string/sishutu" 44 android:textSize="20dp" 45 app:layout_constraintLeft_toLeftOf="parent" 46 app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="400dp" 47 android:layout_marginLeft="16dp"/> 48 <TextView 49 android:id="@+id/shushiText" 50 android:layout_width="wrap_content" 51 android:layout_height="wrap_content" 52 android:text="@string/shushi" 53 android:textSize="20dp" 54 app:layout_constraintLeft_toLeftOf="parent" 55 app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="388dp" 56 android:layout_marginLeft="184dp"/> 57 <TextView 58 android:id="@+id/sumsShunyu" 59 android:layout_width="wrap_content" 60 android:layout_height="wrap_content" 61 android:layout_marginLeft="88dp" 62 android:textSize="25dp" 63 android:textColor="@color/blue" 64 android:hint="表示" 65 app:layout_constraintLeft_toLeftOf="parent" 66 app:layout_constraintTop_toTopOf="parent" 67 android:layout_marginTop="352dp"/> 68 <TextView 69 android:id="@+id/sumsiSishutu" 70 android:layout_width="wrap_content" 71 android:layout_height="wrap_content" 72 android:layout_marginLeft="88dp" 73 android:textSize="25dp" 74 android:textColor="@color/red" 75 android:hint="表示" 76 app:layout_constraintLeft_toLeftOf="parent" 77 app:layout_constraintTop_toTopOf="parent" 78 android:layout_marginTop="400dp"/> 79 <TextView 80 android:id="@+id/shuushi" 81 android:layout_width="wrap_content" 82 android:layout_height="wrap_content" 83 android:textSize="25dp" 84 android:hint="表示" 85 app:layout_constraintLeft_toLeftOf="parent" 86 app:layout_constraintTop_toTopOf="parent" 87 android:layout_marginTop="380dp" android:layout_marginLeft="276dp"/> 88 <android.support.design.widget.BottomNavigationView 89 android:id="@+id/navigation" 90 android:layout_width="0dp" 91 android:layout_height="wrap_content" 92 android:layout_marginEnd="0dp" 93 android:layout_marginStart="0dp" 94 android:background="?android:attr/windowBackground" 95 app:layout_constraintBottom_toBottomOf="parent" 96 app:layout_constraintLeft_toLeftOf="parent" 97 app:layout_constraintRight_toRightOf="parent" 98 app:menu="@menu/navigation"/> 99 100</android.support.constraint.ConstraintLayout>

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問