2013-08-21 27 views
0

我很開始與android和我有我的列表視圖的問題。與數據庫和固定值的Android列表視圖

所以我從數據庫中獲得listview值,那些工作正常。但是我想在將這些值顯示給用戶之前編輯其中的一個值,並且在多次失敗之後,我懇請您的建議。

這裏是我的獲取數據,並將其顯示在列表視圖

listSquad=(ListView)findViewById(R.id.listview);    

     String[] arrayColumns = new String[]{"sq_pos", "sq_name", "sq_born", "sq_gam", "sq_goal"}; 

     int[] arrayViewID = new int[]{R.id.pos,R.id.name,R.id.age,R.id.games,R.id.goals}; 

      DBAdapter db = new DBAdapter(this); 
      db.open(); 
      Cursor c; 
      c = db.doQuery("squad", null, null, null, null, null, "sq_name"); 

      SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.team_list_lay, c, arrayColumns, arrayViewID); 
      listSquad.setAdapter(adapter);   

所以我想借「sq_born」列的值,並改變它,然後在列表視圖中顯示的代碼。該列是整數。

+0

請參考下面的[鏈接] [1] [1]:http://stackoverflow.com/questions/4776936/modify-simplecursoradapters-data –

+0

Thanks Aditya Rai!我使用了視窗,並得到這個工作。 – Gioberti

回答

1

喜歡由阿迪蒂亞拉伊建議中,我使用viewbinder象下面這樣:

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { 
      public boolean setViewValue(View view, Cursor cursor, int column) { 
       if(view.getId() == R.id.age){ 
        //do something here 
        TextView text = (TextView)view; 
        //set text in here      
        text.setText("blaah");                   
        return true; 
       } 
       return false; 
      } 
     });