2012-05-21 64 views
0

我在我的应用程序中使用数据库,因为我已经从数据库中获取数据,但是我不知道如何在textview中显示它。从数据库列表视图

这里是我的代码:

super.onCreate(savedInstanceState); 
    setContentView(R.layout.report); 
    db.open(); 
    Cursor c = db.getAllTitles(); 
    startManagingCursor(c); 
    String[] from = new String[] { db.KEY_INCOME }; 
    int[] to = new int[] { R.id.textView1 }; 
    SimpleCursorAdapter notes = 
       new SimpleCursorAdapter(this, R.layout.report, c, from, to); 

这里的音符在数据库value.But不知道如何着手如何在列表视图中显示。

回答

0

你需要找到你的listview并设置你的适配器。如果您使用的是ListActivity(或ListFragment)(假设你没有使用ListActivity)

ListView list = (ListView) this.findViewById(R.id.yourlistview); 
list.setAdapter(notes); 

,它作为框架假设你使用的是某个ID,您只需将适配器设置像这样的更简单:

setListAdapter(notes); 
0

做这样

String[] titles= new String[] {c.TITLE }; 

     int[] view = new int[] { R.id.textview };  

     SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_example_entry, c, titles, view); 

listview.setAdapter(注);

0

,如果你想设置设置Tesxt列表项点击,你可以做IY喜欢

@Override 
     protected void onListItemClick(ListView l, View v, int position, long id) { 
      Cursor c = (Cursor) arg0.getAdapter().getItem(arg2); 


tv.setTextt(c.getString(1)); 

    }