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

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

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

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

Android Studio

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

Q&A

解決済

1回答

2991閲覧

RecycleViewで一ページに一つの行しか表示されない

Aies

総合スコア21

Java

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

Android Studio

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

0グッド

0クリップ

投稿2019/01/29 01:49

RecycleViewの表示で一ページに一つの行しか表示されません。下にスクロールすれば次の行は出てくるのですが、それでは見にくいので直したいです。heightを設定すれば直るというのも試したのですが、直らなかったので、よろしければご助言お願いいたします。
この機能としては GridViewのカレンダーの日付をクリックすると、その日付がおくられ、日付ごとに格納されているデータを取り出して一覧として表示する、という機能です。

Java

1DailyData 2 3public class DailyData extends AppCompatActivity { 4 5 private TextView mTextMessage; 6 7 private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener 8 = new BottomNavigationView.OnNavigationItemSelectedListener() { 9 10 @Override 11 public boolean onNavigationItemSelected(@NonNull MenuItem item) { 12 switch (item.getItemId()) { 13 case R.id.navigation_input: 14 mTextMessage.setText(R.string.title_home); 15 return true; 16 case R.id.navigation_calendar: 17 mTextMessage.setText(R.string.title_dashboard); 18 return true; 19 case R.id.navigation_config: 20 mTextMessage.setText(R.string.title_notifications); 21 return true; 22 } 23 return false; 24 } 25 }; 26 27 private KakeiboDatabase kDB; 28 private RecyclerView mRecyclerView; 29 private RecyclerView.Adapter mAdapter; 30 String date; 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 setContentView(R.layout.activity_daily_data); 36 37 kDB = new KakeiboDatabase(getApplicationContext()); 38 39 mRecyclerView = (RecyclerView)findViewById(R.id.recyclerView); 40 DailyAdapter dailyAdapter = new DailyAdapter(this.createDataset()); 41 42 LinearLayoutManager llm = new LinearLayoutManager(this); 43 44 mRecyclerView.setHasFixedSize(true); 45 mRecyclerView.setLayoutManager(llm); 46 mRecyclerView.setAdapter(dailyAdapter); 47 48 DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), 49 new LinearLayoutManager(getApplication()).getOrientation()); 50 mRecyclerView.addItemDecoration(dividerItemDecoration); 51 52 53 } 54 55 private ArrayList<Daily> createDataset() { 56 57 Intent intent = getIntent(); 58 date = intent.getStringExtra("CalendarID"); 59 60 Daily daily = new Daily(); 61 ArrayList<Daily> dataset = new ArrayList<>(); 62 63 SQLiteDatabase db = kDB.getReadableDatabase(); 64 65 Cursor cursor = db.query( 66 "kakeibodb", 67 new String[] {"category", "memo", "price"}, 68 "date=?", 69 new String[] {date}, 70 null, 71 null, 72 null); 73 74 boolean next = cursor.moveToFirst(); 75 while (next) { 76 // 取得したカラムの順番(0から始まる)と型を指定してデータを取得する 77 daily.setCategory(cursor.getString(0));// categoryを取得 78 daily.setMemo(cursor.getString(1));// memoを取得 79 daily.setPrice(cursor.getInt(2));// priceを取得 80 81 // 次の行が存在するか確認 82 next = cursor.moveToNext(); 83 dataset.add(daily); 84 } 85 cursor.close(); 86 87 return dataset; 88 } 89}

Java

1Daily 2 3public class Daily { 4 long id; 5 private String category; 6 private String memo; 7 private int price; 8 9 public long getId() { 10 return id; 11 } 12 13 public void setId(long id) { 14 this.id = id; 15 } 16 17 public String getCategory(){ 18 return category; 19 } 20 21 public void setCategory(String category){ 22 this.category = category; 23 } 24 25 public String getMemo() { 26 return memo; 27 } 28 29 public void setMemo(String memo) { 30 this.memo = memo; 31 } 32 33 public int getPrice(){ 34 return price; 35 } 36 37 public void setPrice(int price){ 38 this.price=price; 39 } 40 41}

Java

1activity_daily_data layout 2 3<android.support.constraint.ConstraintLayout 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=".DailyData"> 10 11 <android.support.v7.widget.RecyclerView 12 android:id="@+id/recyclerView" 13 android:layout_width="394dp" 14 android:layout_height="662dp" 15 android:layout_marginStart="8dp" 16 android:layout_marginLeft="8dp" 17 android:layout_marginTop="8dp" 18 android:layout_marginEnd="8dp" 19 android:layout_marginRight="8dp" 20 android:layout_marginBottom="8dp" 21 app:layout_constraintBottom_toBottomOf="parent" 22 app:layout_constraintEnd_toEndOf="parent" 23 app:layout_constraintHorizontal_bias="0.0" 24 app:layout_constraintStart_toStartOf="parent" 25 app:layout_constraintTop_toTopOf="parent" 26 app:layout_constraintVertical_bias="0.0" /> 27 28 <android.support.design.widget.BottomNavigationView 29 android:id="@+id/navigation" 30 android:layout_width="0dp" 31 android:layout_height="wrap_content" 32 android:layout_marginStart="0dp" 33 android:layout_marginEnd="0dp" 34 android:background="?android:attr/windowBackground" 35 app:layout_constraintBottom_toBottomOf="parent" 36 app:layout_constraintLeft_toLeftOf="parent" 37 app:layout_constraintRight_toRightOf="parent" 38 app:menu="@menu/navigation" /> 39</android.support.constraint.ConstraintLayout>

Java

1cell layout 2 3<?xml version="1.0" encoding="utf-8"?> 4<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 5 android:orientation="vertical" android:layout_width="match_parent" 6 android:layout_height="match_parent"> 7 8 <LinearLayout 9 android:orientation="horizontal" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent"> 12 13 <TextView 14 android:layout_width="0dp" 15 android:layout_height="48dp" 16 android:text="New Text" 17 android:id="@+id/dCategory" 18 android:textSize="30dp" 19 android:layout_weight="2" /> 20 21 <TextView 22 android:layout_width="0dp" 23 android:layout_height="48dp" 24 android:text="New Text" 25 android:id="@+id/dMemo" 26 android:textSize="30dp" 27 android:layout_weight="2" /> 28 29 <TextView 30 android:layout_width="0dp" 31 android:layout_height="48dp" 32 android:text="New Text" 33 android:id="@+id/dPrice" 34 android:textSize="30dp" 35 android:layout_weight="1" /> 36 </LinearLayout> 37 38</LinearLayout>

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

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

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

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

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

guest

回答1

0

ベストアンサー

各セルの高さ(layout_height)を match_parent に設定しているのが原因だと思います。
wrap_content もしくは適切な高さを設定するように修正してみてください。

投稿2019/01/29 09:15

kakajika

総合スコア3131

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

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

Aies

2019/01/30 00:40

おっしゃられた通りwrap_contentに直したらできました!ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問