ListViewに選択した日付に格納されたデータを表示するという処理なのですが、エラーも起きず、画面が表示されません。表示の位置を変えたり、レイアウトファイルをまとめるなどやってみたのですが、全くわからなかったのでよろしければご助言いただきたいです。
Java
1@Override 2 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 3 Intent intent = new Intent(getApplication(), DailyData.class); 4 mDateManager = new DateManager(); 5 dateArray = mDateManager.getDays(); 6 String date = titleText.getText().toString().substring(0,7); 7 date = date + "-" + dateArray.get(position).toString().substring(8,10); 8 intent.putExtra("CalendarID", date); 9 startActivity(intent); 10 }
Java
1public class DailyData extends AppCompatActivity { 2 3 private TextView mTextMessage; 4 5 private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener 6 = new BottomNavigationView.OnNavigationItemSelectedListener() { 7 8 @Override 9 public boolean onNavigationItemSelected(@NonNull MenuItem item) { 10 switch (item.getItemId()) { 11 case R.id.navigation_input: 12 mTextMessage.setText(R.string.title_home); 13 return true; 14 case R.id.navigation_calendar: 15 mTextMessage.setText(R.string.title_dashboard); 16 return true; 17 case R.id.navigation_config: 18 mTextMessage.setText(R.string.title_notifications); 19 return true; 20 } 21 return false; 22 } 23 }; 24 25 private KakeiboDatabase kDB; 26 ListView listView; 27 28 String date; 29 @Override 30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 setContentView(R.layout.activity_daily_data); 33 34 listView = new ListView(this); 35 36 kDB = new KakeiboDatabase(getApplicationContext()); 37 38 ArrayList<Daily> list = new ArrayList<>(); 39 DailyAdapter dailyAdapter = new DailyAdapter(DailyData.this); 40 41 Intent intent = getIntent(); 42 date = intent.getStringExtra("CalendarID"); 43 44 Daily daily = new Daily(); 45 46 SQLiteDatabase db = kDB.getReadableDatabase(); 47 48 Cursor cursor = db.query( 49 "kakeibodb", 50 new String[] {"category", "memo", "price"}, 51 "date=?", 52 new String[] {date}, 53 null, 54 null, 55 null); 56 57 boolean next = cursor.moveToFirst(); 58 while (next) { 59 // 取得したカラムの順番(0から始まる)と型を指定してデータを取得する 60 daily.setCategory(cursor.getString(0));// categoryを取得 61 daily.setMemo(cursor.getString(1));// memoを取得 62 daily.setPrice(cursor.getInt(2));// priceを取得 63 64 // 次の行が存在するか確認 65 next = cursor.moveToNext(); 66 list.add(daily); 67 dailyAdapter.notifyDataSetChanged(); 68 } 69 cursor.close(); 70 71 dailyAdapter.setDailyList(list); 72 listView.setAdapter(dailyAdapter); 73 } 74}
Java
1public class DailyAdapter extends BaseAdapter { 2 3 Context context; 4 LayoutInflater layoutInflater = null; 5 ArrayList<Daily> dailyList; 6 7 public DailyAdapter(Context context) { 8 this.context = context; 9 this.layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 10 } 11 12 public void setDailyList(ArrayList<Daily> dailyList) { 13 this.dailyList = dailyList; 14 } 15 16 @Override 17 public int getCount() { 18 return dailyList.size(); 19 } 20 21 @Override 22 public Object getItem(int position) { 23 return dailyList.get(position); 24 } 25 26 @Override 27 public long getItemId(int position) { 28 return dailyList.get(position).getId(); 29 } 30 31 @Override 32 public View getView(int position, View convertView, ViewGroup parent) { 33 convertView = layoutInflater.inflate(R.layout.list_cell,parent,false); 34 35 ((TextView)convertView.findViewById(R.id.dCategory)).setText(dailyList.get(position).getCategory()); 36 ((TextView)convertView.findViewById(R.id.dMemo)).setText(dailyList.get(position).getMemo()); 37 ((TextView)convertView.findViewById(R.id.dPrice)).setText(String.valueOf(dailyList.get(position).getPrice())); 38 39 return convertView; 40 } 41}
Java
1package com.example.a162105.kakeibo; 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}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。