listview中的sqlite数据库记录

时间:2013-08-22 12:48:34

标签: android sqlite android-listview android-arrayadapter

我正在创建一个包含sqlite数据库数据的listview。我运行程序三次,所以我的数据库中现在有3条记录。在运行程序时,我看到3个列表行,但不显示文本。

这是我的分类活动类

  

`public class CategoryActivity扩展了ListActivity {

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



    CategorySQLHelper categorysql = new CategorySQLHelper(this);
    Log.d("insert:", "inserting into database");
    categorysql.addCategory(new Category("Science"));


    //get all category
    Log.d("reading", "reading all category");
    List<Category>category=categorysql.getAllCategory();

    for(Category categories: category){
        String categoryname=categories.getCategory();
        Log.d("categories", categoryname);
    }

    ArrayAdapter<Category> adapter = new ArrayAdapter<Category>(getApplicationContext(), android.R.layout.simple_list_item_1,category);
    setListAdapter(adapter);
}`

1 个答案:

答案 0 :(得分:0)

使用活动上下文

ArrayAdapter<Category> adapter = new ArrayAdapter<Category>(CateogryActivity.this, android.R.layout.simple_list_item_1,category);
setListAdapter(adapter);

When to call activity context OR application context?