2010-06-22 97 views
-2
public class List_View extends ListActivity { 

    private TextView toptext; 
    private TextView bottomtext; 

    DBAdapter db = new DBAdapter(this); 

    public void onCreate(Bundle icicle) 
    { 
     super.onCreate(icicle); 
     setContentView(R.layout.list); 
     getData(); 

     toptext = (TextView) findViewById(R.id.toptext); 
     bottomtext = (TextView) findViewById(R.id.bottomtext); 

    } 

    private void getData() {    
      db.open(); 

      Cursor c = db.getAllEntry(); 
      c.moveToFirst(); 

      ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.view_list, c, new String[] {"date", "title"}, new int[] {R.id.toptext, R.id.bottomtext}); 

      bottomtext.setText(c.getString(1)); 
      toptext.setText(c.getString(4)); 

      setListAdapter(adapter); 

      db.close(); 
    } 

} 

我想將存儲的數據從數據庫顯示到ListView中。使用ListAdapter顯示數據庫數據

僅標題和日期。

+4

請考慮花些時間在這裏解決其他問題。沒有一個都是用大寫字母寫的,或者需要「幫助」這個詞 - 這是一個問答網站,因此「幫助」是多餘的。另外,使用「URGENT :(」這樣的短語不會幫助您更快地獲得幫助 – nickf 2010-06-22 06:18:32

+2

...然後,請告訴我們您的問題到底是什麼。您似乎已經有了一段代碼,但不幸的是所以請解釋一下代碼試圖做什麼以及實際結果是什麼順便說一句:這裏的問題幾乎總是*回答的很快,*如果*你花時間來制定你的問題,以便讀者立即理解它 – chiccodoro 2010-06-22 06:20:13

+0

因爲我真的很害怕這個答案,問題是我似乎無法在列表視圖中顯示我的數據在我想要的列表視圖中! – UserA 2010-06-22 06:35:39

回答

0

只是看了看它;您的getData調用位於toptext和bottomtext設置之前。