Android的SQLite的绑定到GridView控件在Eclipse [英] Android Binding SQLite to GridView in Eclipse

查看:150
本文介绍了Android的SQLite的绑定到GridView控件在Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了以下code从SQLite数据库retrive数据。

I have made the following code to retrive data from SQLite database.

public Cursor fetchAllScores() {
    return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
            KEY_PLAYDATE, KEY_NUMVALA, KEY_NUMVALB }, null, null, null,
            null, null);
}

然后用我调用这个函数在我main.java文件中的以下

Then I call this function in my main.java file using the following

cursor = dbHelper.fetchAllScores();
    startManagingCursor(cursor);

有游标后,我设法填充myGridView使用下面的code一些数据

After having cursor I manage to populate myGridView with some data using following code

GridView myGV = (GridView)findViewById(R.id.gridView1);

    String[] cols = new String[] { scoreDbAdapter.KEY_PLAYDATE, scoreDbAdapter.KEY_NUMVALA, scoreDbAdapter.KEY_NUMVALB};
    int[]   views = new int[] { android.R.id.text1, android.R.id.text2, android.R.id.text2 };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_list_item_1, cursor, cols, views);

    Log.w("NumRows",adapter.getCount() + "");

    myGV.setAdapter(adapter);

现在的问题是只第一行填充和前两列,我要像在福斯特行数据(2011年10月27号,5,6)等和第二行(2011年10月26日,3,2)但即时得到是只喜欢(2011-10-27,2011-10-26)福斯特一行。

Now the problem is only first row is populated and first two columns, I want data like in forst row (2011-10-27 , 5 , 6 ) and second row like (2011-10-26 , 3 , 2 ) but i m getting is only forst row like (2011-10-27, 2011-10-26 ).

这个问题能解决的GridView的?

Can this be fixed in GridView?

推荐答案

请一个新的布局,其中包含textViews。查找布局如在下面的code第一线,你的数据附加到ListView。 ListView控件加载含有TextView的布局。

Make a new layout which contains textViews. Find the layout as shown in first line of the code below and attach your data to the listView. ListView loads the layout containing textView.

private void populateGrid()
{

    ListView lv = (ListView)findViewById(R.id.listView1);

    Cursor c = dbHelper.fetchAllScores();
    startManagingCursor(cursor);

    String[] cols = new String[] { TodoDbAdapter.KEY_PLAYDATE, TodoDbAdapter.KEY_NUMVALA, TodoDbAdapter.KEY_NUMVALB};
    int[]   views = new int[] { R.id.txt_date, R.id.txt_no, R.id.txt_yes};

    // Now create an array adapter and set it to display using our row
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            R.layout.listviewtemp, c, cols, views);

    Log.w("NumRows",adapter.getCount() + "");

    lv.setAdapter(adapter);

}

R.layout.listviewtemp是ListView控件模板布局(单独的XML),LV是在mainlayout.xml发现列表视图。

R.layout.listviewtemp is the listView template layout (separate xml), lv is the listview found in the mainlayout.xml.

public Cursor fetchAllScores() {
    return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
            KEY_PLAYDATE, KEY_NUMVALA, KEY_NUMVALB }, null, null, null,
            null, null);
}

这篇关于Android的SQLite的绑定到GridView控件在Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆