2012-04-11 48 views
0

這是我的數據庫處理程序代碼..與導航鍵的Android的ListView ...需要幫助

    // Getting All detail 
        public List<Detail> getAllDetail() { 
         List<Detail> detailList = new ArrayList<Detail>(); 
         // Select All Query 
         String selectQuery = "SELECT * FROM " + TABLE_DETAIL; 

         SQLiteDatabase db = this.getWritableDatabase(); 
         Cursor cursor = db.rawQuery(selectQuery, null); 

         // looping through all rows and adding to list 
         if (cursor.moveToFirst()) { 
          do { 
           Detail detail = new Detail(); 
           detail.setID(Integer.parseInt(cursor.getString(0))); 
           detail.setTitle(cursor.getString(1)); 
           detail.setDetail(cursor.getString(2)); 

           // Adding contact to list 
           detailList.add(detail); 
          } while (cursor.moveToNext()); 
         } 

我需要在一個活動類,其佈局文件看起來像一個按鈕樣的一個列表視圖檢索這些細節這個..

enter image description here

按鈕應該被分配數據庫行..點擊它應該去另一個活動,其中特定行的細節視圖完全時的ID ..

請幫助我..在此先感謝..

回答

0

此列表視圖?或者您是否創建了自己的佈局?如果這是列表視圖,那麼您已經擴展了適配器類,並從那裏您可以編寫這些按鈕的點擊偵聽器。但是如果它不是適配器,那麼你需要編寫自己的點擊監聽器,並且需要將它提供給列表中的每個按鈕。

希望這會幫助你。

感謝

+0

不行。這是一個樣。我需要的東西鏈路上,這..請幫助他在如何實現這個.. – 2012-04-11 13:14:31

+0

好吧,如果你從遊標獲取所有數據,那麼我們有遊標適配器,併爲此我們有Android SDK示例中的示例應用程序。只要看看它,你就會對它有完整的想法。 – 2012-04-12 07:00:35

0

我通過創建按鈕和TextView的動態線性佈局得到了解決自己..

RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativeLayout3); 

     final DatabaseHandler dbpin = new DatabaseHandler(this); 
     Log.d("Reading: ", "Reading all tasks.."); 
      List<Task> task1 = dbpin.getAllTask();  

      for (Task cn : task1) { 
       String log = cn.getTitle(); 
      int i = cn.getID(); 


      Button button = new Button(this); 
        button.setText("View" + i); 
       button.setTextSize(10); 

       button.setId(2000 + i); 
       int width = 80; 
       int height = 60; 


       TextView textview = new TextView(this); 
       textview.setText(log); 
       textview.setWidth(200); 
       textview.setTextSize(20); 
       textview.setPadding(0, 10, 0, 0); 
       textview.setId(2000 + i); 
      }