Android 禁用按钮并存储在数据库中
我正在为5、6部不同电影的同一活动打电话订票。我已经用钮扣做座位了。我在单击后设置按钮禁用,并将其id存储在sql数据库中。现在,当我再次为同一部电影、同一个节目预定另一张票时Android 禁用按钮并存储在数据库中,android,Android,我正在为5、6部不同电影的同一活动打电话订票。我已经用钮扣做座位了。我在单击后设置按钮禁用,并将其id存储在sql数据库中。现在,当我再次为同一部电影、同一个节目预定另一张票时 String[] projection= new String[]{ movieEntry.COLUMN_NAME_SEAT }; //where clause String selection=movieEntry.COLUMN_NAME_
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);
}
}*/
String[]投影=新字符串[]{
movieEntry.COLUMN\u NAME\u座位
};
//where子句
字符串选择=movieEntry.COLUMN_NAME_MN+“=?”+”和“+movieEntry.COLUMN_NAME_MD+”=?“+”和“+movieEntry.COLUMN_NAME_MT+”=?”;
//int i=0;
字符串colindex=null;
//此查询是select seatno from tablename
//其中movie\u name='用户选择的电影'和movie\u time='用户当前选择的电影'
//和电影_date='';
//它在提取所有记录时工作正常
//我试图将所有这些获取的seatno添加到seatsArraylist中,以便
//我们可以从这个arrayList中获取它,并为用户禁用该特定电影的座位以及日期和时间
//但问题是它只向arraylist添加了一条记录
//你能检查一下这个密码吗
字符串[]selectionArgs={Movietitle,Datem,Mtiming};
试一试{
Cursor=rdb.query(
movieEntry.TABLE_名称,
投影,
选择,
精选,
无效的
无效的
无效的
);
如果(光标!=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您不应该像刚才那样在光标中进行迭代,使光标移动到第一部分(第0部分)。要在光标中进行迭代,使用for循环很容易:
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
// all operations should be here
}
同样,即使在循环内部,方法cursor.getString(int)
传递的int
也不是游标的索引,而是列索引。在表中可能有多个列,第一列是(0th),第二列是(1st)。所以您应该传递列索引。什么是i
?您正在为每一行递增它,但使用它作为列索引…您知道基本游标api吗?