2012-03-02 18 views
-1

我已經實現了一個應用程序來從本地移動SQLite數據庫獲取數據,並嘗試發送到Custome簡單光標適配器類。我從BroadCast Reciever接收數據它用於從DB獲取最新記錄。如果使用SimpleCursorAdapter,那麼我可以從Sqlite數據庫獲取數據並更新爲UI.But但無法將數據庫內容傳遞給CustomeSimpleCursorAdapter.So如何將db內容傳遞給CustomeSimpleCursorAdapter?如何從SQLite中將數據從Custome Simple Cursor適配器中獲取並顯示在列表中?

我已經實現的代碼如下:

 private BroadcastReceiver myReceiver = new BroadcastReceiver() 
    { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
     msh = new MySqliteHelper(GetMsgsScreen.this); 
     msh.openToWrite(); 
     lst = ((ListView)findViewById(R.id.listView1)); 
     cursor = msh.queueAll(); 
     getFromDB = new String[]{MySqliteHelper.USER_NAME,MySqliteHelper.USER_MESSAGE}; 
     toView = new int[]{R.id.usrName,R.id.msgText}; 
     cursor.moveToFirst(); 
      lst.setAdapter(new SimpleCursorAdapter(GetMsgsScreen.this, R.layout.test, cursor, getFromDB, toView));    
     updateList(); 

     } 
    }; 

同樣,

如果我使用CustomeSimpleCursorAdapter代替SimpleCursorAdapter然後我怎樣才能顯示 MySqliteHelper.USER_NAMEMySqliteHelper.USER_MESSAGE內容清單? 請任何機構幫助我。

+0

-1不CustomeSimpleCursorAdapter定義,我們只能猜測該怎麼辦呢?我的第一個猜測是..你沒有爲CustomeSimpleCursorAdapter ... – Selvin 2012-03-02 10:00:11

+0

提供適當的構造嘿看,有人給予適當answer.y你放棄了嗎? – 2012-03-02 10:08:57

回答

1

如果要創建CursorAdapter的自定義適配器子類,則必須覆蓋bindViewnewView方法。

public class CustomCursorAdapter extends CursorAdapter { 
    public CustomCursorAdapter(Context context, Cursor c) { 
     super(context, c); 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     TextView username = (TextView)view.findViewById(R.id.username); 
     username.setText(cursor.getString(
       cursor.getColumnIndex(MySqliteHelper.USER_NAME))); 
     // Set up other view here 
     // ... 
    } 

    @Override 
    public View newView(Context context, Cursor cursor, ViewGroup parent) { 
     LayoutInflater inflater = LayoutInflater.from(context); 
     View v = inflater.inflate(R.layout.listItem, parent, false); 
     bindView(v, context, cursor); 
     return v; 
    } 
} 
+0

我們可以得到像LazyLoad圖片加載的圖片嗎? – 2012-03-02 11:22:26

相關問題