0

-これは、これまでの入力のレイアウトです-

<?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="wrap_content"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/etClassName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:hint="@string/className"/>


    <EditText
        android:id="@+id/etAssignmentName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:ems="10" 
        android:hint="@string/assignmentName"/>

    <EditText
        android:id="@+id/etDueDate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_marginBottom="20dp"
        android:hint="@string/dueDate" />


    <EditText
        android:id="@+id/etNotes"
        android:layout_width="match_parent"
        android:layout_height="194dp"
        android:ems="10"
        android:inputType="textMultiLine"
        android:layout_marginBottom="5dp" 
        android:hint="@string/notes"/>


    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">
        <Button
            android:id="@+id/bAddAssignments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/addAssignment"
            android:layout_weight="1" />

        <Button
            android:id="@+id/bViewAssignments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/viewAssignments" 
            android:layout_weight="1"/>
    </LinearLayout>
</LinearLayout>

-[追加]ボタンをクリックすると、このページが表示されます。このページには、クリックして割り当てを表示できる割り当て名が一覧表示されます-

<?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="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.63" >
    </ListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/bNewAssignment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/newAssignment" />

        <Button
            android:id="@+id/bdeleteAssignment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/deleteAssignment" />
    </LinearLayout>

</LinearLayout>

私の問題は、最初のレイアウトがデータを追跡しているときに、2番目のレイアウトにデータを入力する方法がわからないことです。2番目のレイアウトは、リストビューに入力するためにユーザーが入力した内容などをどのように認識しますか

現在、dbadapterクラス(ヘルパークラスを内部に含む)、entryクラス(エントリオブジェクトを作成する)、およびassignmentclass(リストビューを表示することを想定)があります。

何かアイデアはありますか?

4

2 に答える 2

1

必要なデータを Intent バンドルで渡します。

インテントを設定するときは、必要なデータを次のクラスに余分に入れます (ここでは文字列を想定していますが、他の形式にすることもできます)。

Intent myIntent = new Intent(YourActivity.this, NewActivity.class);
myIntent.putExtra("Data1", data1var);
myIntent.putExtra("Data2", data2var);
YourActivity.this.startActivity(myIntent);

新しいクラスでは:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String value1 = extras.getString("Data1");
        String value2 = extras.getString("Data2");
    }
    //use your passed strings
}      
于 2012-06-25T14:22:38.000 に答える
0

問題の説明はかなりあいまいです。Lars Vogella が SQLLite を ListView と一緒に使用する方法について作成したチュートリアルの 1 つを紹介します。彼らはすべてを素晴らしく簡単に説明します。きっとあなたの答えがそこにあるはずです!

アップデート:

InputActivity の追加ボタンの onClickListener:

  • ユーザー入力をデータベースに追加します (DatabaseHelper を使用)
  • リスト アイテム ListView を含む 2 番目のアクティビティを開始します

ListActivity の onCreate:

  • たとえば、配列を作成します
  • DatabaseHelper に、データベースに必要なレコードを配列に入力させます
  • 配列を埋めてアダプタを作成します
于 2012-06-25T14:06:01.167 に答える