禁用按钮并存储在数据库中

时间:2017-11-26 20:44:38

标签: android

我正在为5,6种不同的电影调用相同的活动来预订机票。我用过座椅按钮。单击后设置按钮禁用并将其id保存在sql数据库中。现在,当我再次预订同一部电影的另一张票时,同样的节目

String[] projection= new String[]{
                movieEntry.COLUMN_NAME_SEAT
        };
        //where clause
        String selection=movieEntry.COLUMN_NAME_MN + " =?"+" AND "+movieEntry.COLUMN_NAME_MD +" =?" +" AND "+movieEntry.COLUMN_NAME_MT +" =?" ;
         // int i=0;
          String colindex=null;
          // this query is select seatno from tablename
        // where movie_name='movie that user selected' and movie_time='user seklected currently'
        //and movie_date='';
        //it is working correctly its fetching all records
        // i am trying to add all this fetched seatno to the seatsArraylist so that
        //we can get it from this arrayList and disable that seats for the user for that particular movie and date and time
        // but problem is that it is adding only one records to arraylist
        //can you plz go through this code
          String[] selectionArgs ={ Movietitle, Datem, Mtiming} ;
          try{
              Cursor cursor = rdb.query(
                      movieEntry.TABLE_NAME,
                      projection,
                      selection,
                      selectionArgs,
                      null,
                      null,
                      null
              );
              if(cursor!= null ) {
                   int i=0;
                  while(cursor.moveToFirst())
                  {
                    colindex= cursor.getString(i);
                      seatsArrayList.add(colindex);
                      i++;
                     tv1.setText(seatsArrayList.get(2));
                  }
                  tv.setText(colindex);
              }
             /* for(int j=0;j<=seatsArrayList.size();j++)
              {
                  if(seatsArrayList.get(j)=="Seat4")
                  {
                      theBtn[3].setEnabled(false);

                  }
              }*/

1 个答案:

答案 0 :(得分:0)

您不应该像在光标移动到第一部分(第0部分)那样迭代光标。要在游标中迭代,可以使用for循环进行迭代:

for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
// all operations should be here
}

甚至在循环内部,传递的cursor.getString(int)方法int不是游标的索引,而是列索引。在您的表中,可能有多列,第一列是(第0列),第二列是(第1列)。所以你应该传递列索引。