Android 创建具有可访问内容的表

Android 创建具有可访问内容的表,android,sqlite,Android,Sqlite,我对android编码很陌生,让我们来描述一下我想做什么,我在我的应用程序中创建了一个sqlite数据库和一个表,它有5个元素:(课程名称、上课日期、上课时间、地点、考试时间) 问题是,我如何制作这样的布局: 右边有时间,上面有天,我希望每个表的内容都可以访问,我的意思是,如果有人在我的数据库中添加了一个表行,其中包含以下内容:(数学,星期天,11:00,大学,测试) 然后数学题的名字,在太阳下,11:00 你知道我该怎么做吗? 谢谢此代码不是即插即用的,您可能还需要在此处进行一些修改。 创建

我对android编码很陌生,让我们来描述一下我想做什么,我在我的应用程序中创建了一个sqlite数据库和一个表,它有5个元素:(课程名称、上课日期、上课时间、地点、考试时间) 问题是,我如何制作这样的布局:

右边有时间,上面有天,我希望每个表的内容都可以访问,我的意思是,如果有人在我的数据库中添加了一个表行,其中包含以下内容:(数学,星期天,11:00,大学,测试) 然后数学题的名字,在太阳下,11:00

你知道我该怎么做吗?
谢谢

此代码不是即插即用的,您可能还需要在此处进行一些修改。 创建一个表布局-(我只创建了两行,所以还要创建其他行-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
        android:id="@+id/mon08"
        android:layout_weight="1"
        android:background="#dcdcdc"
        android:gravity="center"
        android:text="Row 2 column 1"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/tue08"
        android:layout_weight="1"
        android:background="#d3d3d3"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 2"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/wed08"
        android:layout_weight="1"
        android:background="#cac9c9"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 3"
        android:textColor="#000000" />
    <TextView
        android:id="@+id/thu08"
        android:layout_weight="1"
        android:background="#cac9c9"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 3"
        android:textColor="#000000" />
    <TextView
        android:id="@+id/fri08"
        android:layout_weight="1"
        android:background="#cac9c9"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 3"
        android:textColor="#000000" />
    <TextView
        android:id="@+id/sat08"
        android:layout_weight="1"
        android:background="#cac9c9"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 3"
        android:textColor="#000000" />
    <TextView
        android:id="@+id/sun08"
        android:layout_weight="1"
        android:background="#cac9c9"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Row 2 column 3"
        android:textColor="#000000" />
</TableRow>
以及设置数据-

private void setData(){
//get day in first three letters like mon, tue and time slots as 08, 09 so it will give mon08, so point to that textview and set your subject.
TextView textView = (TextView)findViewById(getResourceID(day+time));
textView.setText(yourSubject);//set the subject in here.
}

您可以创建自定义BaseAdapter,并在视图中填充数据。并且,无论何时在数据库中添加条目,都可以将该数据从数据库重新提取到ArrayList,然后调用
notifyDataSetChanged()
在你的
适配器上。用谷歌搜索每一步,你就会知道怎么做。如果有任何问题,请问我。@Darpan谢谢你的帮助,但有一个问题,当我搜索时,自定义基本适配器是用于列表视图的,对吗?但是我想要一个表,就像我在这张图片中显示的那样:可以用自定义基本适配器做类似的事情吗BaseAdapter?假设你有七天的时间,假设你的学校从晚上8点到3点工作。那么你将只有7*7=49个字段。你的tableView中不会有更多的框吗?@Darpan是的,没错亲爱的Darpan,这就是我需要在我的应用程序中创建的所有框,没有更多的框。
private int getResourceID (String name){
Resources resources = YourActivity.this.getResources();
final int resourceId = resources.getIdentifier(name, "drawable", 
   YourActivity.this.getPackageName());
return resourceId;
}
private void setData(){
//get day in first three letters like mon, tue and time slots as 08, 09 so it will give mon08, so point to that textview and set your subject.
TextView textView = (TextView)findViewById(getResourceID(day+time));
textView.setText(yourSubject);//set the subject in here.
}