2012-04-11 44 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); 
      }