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>

我的问题是,当我的第一个布局跟踪数据时,我不知道如何填充第二个布局。第二个布局如何知道用户输入的内容等以填充列表视图

我目前有一个 dbadapter 类(里面有帮助类),一个入口类(创建入口对象)和一个 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 一起使用的教程之一。他们解释了一切美好而简单的事情。我相信你会在那里找到你的答案!

更新:

InputActivity中添加按钮的onClickListener:

  • 将您的用户输入添加到数据库(使用 DatabaseHelper)
  • 列表项启动您的第二个活动,包括 ListView

ListActivity 的 onCreate:

  • 例如创建一个数组
  • 让你的 DatabaseHelper 用你想要在数据库中的记录填充数组
  • 创建一个适配器给你填充数组
于 2012-06-25T14:06:01.167 回答