0

テキストビューを分離するために複数のデータベース テーブルを表示する必要があります。

したがって、テーブルからすべての「予定」を取得し、それらを並べ替えて、txtMonday、txtTuesday、txtWednesday などの mainActivity の個別のテキストビューに表示する必要があります。

データベースは、その日をその他の詳細とともに保存するように設計されています。

private static final String DATABASE_CREATE =
        "create table " + TABLE_AP + "(" + COLUMN_ID + " integer primary key autoincrement, "
        + COLUMN_DAY + " text not null, "
        + COLUMN_TIME + " text not null, "
        + COLUMN_DURATION + " text not null, "
        + COLUMN_DESCRIPTION + " text not null);";

これは、MainActivity を介して呼び出す方法です: (onCreate で呼び出すこともできます)

  public void onResume (){
      APData = new AppointmentDataSource(this);
      APData.open();
      List<Appointment> appointments = APData.retrieveAllAppointments();
      APData.close();

AppointmentDataSource:

public List<Appointment> retrieveAllAppointments () {
    List<Appointment> appointments = new ArrayList<Appointment>();

    Cursor cursor = database.query(MySQLiteHelper.TABLE_AP, , null, null, null, null, null);

    cursor.moveToFirst();


    while (!cursor.isAfterLast()) {
        Appointment ap = cursorToBk(cursor);
        appointments.add(ap);
        cursor.moveToNext();
    }

    cursor.close();
    return appointments;        
}

また、日については、ラジオボタンを使用して月曜/火曜/水曜/木曜/金曜のいずれかを選択したので、日を次のように保存します。

createButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        findRadioGroup = (RadioGroup) findViewById(R.id.radioDay);
        int selectedId = findRadioGroup.getCheckedRadioButtonId();
        radioButton = (RadioButton) findViewById(selectedId);


        String day=radioButton.getText().toString();
        String time=txtTime.getText().toString();
        String duration=txtDuration.getText().toString();
        String description=txtDescription.getText().toString();

        APData.insert(day, time, duration, description);
        APData.close();
        finish();
      }

    });

およびそれらの XML/文字列:

<string name="RadioMon">Mon</string>
<string name="RadioTue">Tue</string>
<string name="RadioWed">Wed</string>
<string name="RadioThu">Thur</string>
<string name="RadioFri">Fri</string>
4

1 に答える 1

1

データモデルには、Appointments を操作するクラスが必要です。そのため、データベースからすべての予定を取得するときにappointments[i].Day、Appointment クラスの作成方法に基づいて、またはそのようなものでフィルター処理するだけです。それぞれに対して異なる DB 選択を明示的に作成する必要はありません。

  public void onResume (){
  APData = new AppointmentDataSource(this);
  APData.open();
  List<Appointment> appointments = APData.retrieveAllAppointments();
  APData.close();
  TextView tvMonday = (TextView)findViewById(R.id.tvMonday);
  TextView tvTuesday = (TextView)findViewById(R.id.tvTuesday);
  ... (all your days textViews).
  for(Iterator<Appointment> i = appointments.iterator(); i.hasNext();){ 
  Appointment item = i.next();
     if(item.Day.equals("Monday") tvMonday.append(item.ToString());
     //same for the rest of your textViews
  }

このようなものでなければなりません。

于 2013-04-11T14:39:00.047 に答える