2012-11-27 26 views
0

我有一個ListView從SQLite數據庫加載數據,onClickListener爲每個列表打開一個新的活動。我現在的問題是,當我按下「Back」返回ListView的上一個活動時,它不顯示。Android重新加載來自SQLite的ListView數據

如何重新從數據庫中重新加載列表?我該如何解決它?

它與notifyDataSetChanged()有什麼關係嗎?

請幫忙。

謝謝。

編輯:

下面是我的代碼加載的onCreate()下的ListView:

 ListView listContent = (ListView) findViewById(R.id.contentlist); 
     mySQLiteAdapter = new SQLiteAdapter(this); 
     mySQLiteAdapter.openToRead(); 

     Cursor cursor = mySQLiteAdapter.queueAll(); 
     startManagingCursor(cursor); 

     String[] from = new String[] { SQLiteAdapter.KEY_CONTENT }; 
     int[] to = new int[] { R.id.text }; 

     SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor, from, to); 

     listContent.setAdapter(cursorAdapter); 

     mySQLiteAdapter.close(); 

     //Onclick ListView setlistener 
     listContent.setTextFilterEnabled(true); 
     listContent.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 
       Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class); 
       listTopic = ((TextView) view).getText().toString(); 

       summaryIntent.putExtra("SummTopic", listTopic); 
       startActivity(summaryIntent); 
      } 
     }); 

那麼在簡歷加()?

+1

您應該將加載數據代碼添加到onStart()或onResume()。其餘的是純粹的猜測,因爲你不提供代碼... – WarrenFaith

+0

你可以發佈你的代碼?列表視圖必須顯示您何時按下,這是一個android生命週期問題。當數據庫的內容沒有改變時,不需要從onResume()中的數據庫加載數據。如果數據庫中有很多條目,就會影響性能。 – zennon

+0

@WarrenFaith:查看我的編輯部分的代碼。 – mellissa

回答

2

您可以將代碼從數據庫中提取數據並將其添加到onResume()內的ListView中。所以當你跳回到你以前的Activity時,它的onResume()將被調用,並且你的ListView將被載入來自數據庫的數據。

相關問題