在获取Android应用SQLite表数据 [英] Retrieving sqlite table data in android app
问题描述
我成功地检索在我的Android app.However我的SQLite表数据有哪些我不能够想出一些小问题。
code段:
INT标志= 1;
为(c.moveToFirst();!c.isAfterLast(); c.moveToNext()){ 字符串天= c.getString(c.getColumnIndex(天)); 字符串SLOT1 = c.getString(c.getColumnIndex(7:30-9:10AM));
字符串SLOT2 = c.getString(c.getColumnIndex(9:20-11:00AM));
3号槽位的String = c.getString(c.getColumnIndex(11:10-12:50PM));
串时隙4 = c.getString(c.getColumnIndex(1:40-3:20PM));
字符串slot5 = c.getString(c.getColumnIndex(3:30-5:00));
TR的TableRow =新的TableRow(viewtimetable.this); tr.setLayoutParams(新的LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)); 如果(标志== 1)
{ TextView的COL1 =新的TextView(viewtimetable.this);
col1.setText(日);
col1.setTextColor(Color.BLUE);
col1.setTextSize(15);
tr.addView(COL1);
TextView的COL2 =新的TextView(viewtimetable.this);
col2.setPadding(10,0,0,0);
col2.setTextSize(15);
col2.setText(7:30-9:10AM);
col2.setTextColor(Color.BLUE);
tr.addView(COL2); TextView的COL3 =新的TextView(viewtimetable.this);
col3.setPadding(10,0,0,0);
col3.setText(9:20-11:00AM);
col3.setTextColor(Color.BLUE);
col3.setTextSize(15);
tr.addView(COL3); TextView的COL4 =新的TextView(viewtimetable.this);
col4.setPadding(10,0,0,0);
col4.setText(11:10-12:50PM);
col4.setTextColor(Color.BLUE);
col4.setTextSize(15);
tr.addView(COL4); TextView的COL5 =新的TextView(viewtimetable.this);
col5.setPadding(10,0,0,0);
col5.setText(1:40-3:20PM);
col5.setTextColor(Color.BLUE);
col5.setTextSize(15);
tr.addView(COL5); TextView的COL6 =新的TextView(viewtimetable.this);
col6.setPadding(10,0,0,0);
col6.setText(3:30-5:00);
col6.setTextColor(Color.BLUE);
col6.setTextSize(15);
tr.addView(COL6); tv.addView(TR); 最后查看U电源=新景(viewtimetable.this); vline.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,2));
vline.setBackgroundColor(Color.BLUE); tv.addView(U电源); 标志= 0; } 其他
{ TextView的B =新的TextView(viewtimetable.this);
//字符串STIME = json_data.getString(天);
b.setText(天);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr.addView(二);
TextView的B1 =新的TextView(viewtimetable.this);
TextView的B2 =新的TextView(viewtimetable.this);
TextView的B3 =新的TextView(viewtimetable.this);
TextView的B4 =新的TextView(viewtimetable.this);
TextView的B5 =新的TextView(viewtimetable.this);
b1.setPadding(10,0,0,0);
b1.setTextSize(15);
b1.setTextColor(Color.RED);
b2.setPadding(10,0,0,0);
b2.setTextColor(Color.RED);
b2.setTextSize(15);
b3.setPadding(10,0,0,0);
b3.setTextColor(Color.RED);
b3.setTextSize(15);
//tr.addView(b3); b4.setPadding(10,0,0,0);
b4.setTextColor(Color.RED);
b4.setTextSize(15);
//tr.addView(b4); b5.setPadding(10,0,0,0);
b5.setTextColor(Color.RED);
b5.setTextSize(15);
//tr.addView(b5); 如果(day.equals(星期一))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期二))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} }
否则,如果(day.equals(星期三))
{
如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} }
否则,如果(day.equals(星期四))
{
如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期五))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期六))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } tr.addView(B1);
tr.addView(B2);
tr.addView(B3);
tr.addView(B4);
tr.addView(B5);
tv.addView(TR);
结果:
问:
我不知道为什么没有得到显示周五的行?
P.S:因为我已经成功地检索,除了周五的数据所需的所有数据,因此有上述code段的一些小问题,只有我猜
编辑:
问题出在别的block.As第一数据,周五和else块没有得到第一次迭代因此,问题就出现了执行。
尝试删除else块并生成异常
指定的子已经有parent.you必须在孩子的父母先调用removeView()。
解决方案:
我所做的是在循环中我创建了一个新的的TableRow
,然后添加的意见
到该行。
最终修正code:
TableLayout电视=(TableLayout)findViewById(R.id.table);
tv.removeAllViewsInLayout();
INT标志= 1;
TR的TableRow =新的TableRow(viewtimetable.this); tr.setLayoutParams(新的LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)); TextView的COL1 =新的TextView(viewtimetable.this);
col1.setText(日);
col1.setTextColor(Color.BLUE);
col1.setTextSize(15);
tr.addView(COL1);
TextView的COL2 =新的TextView(viewtimetable.this);
col2.setPadding(10,0,0,0);
col2.setTextSize(15);
col2.setText(7:30-9:10AM);
col2.setTextColor(Color.BLUE);
tr.addView(COL2); TextView的COL3 =新的TextView(viewtimetable.this);
col3.setPadding(10,0,0,0);
col3.setText(9:20-11:00AM);
col3.setTextColor(Color.BLUE);
col3.setTextSize(15);
tr.addView(COL3); TextView的COL4 =新的TextView(viewtimetable.this);
col4.setPadding(10,0,0,0);
col4.setText(11:10-12:50PM);
col4.setTextColor(Color.BLUE);
col4.setTextSize(15);
tr.addView(COL4); TextView的COL5 =新的TextView(viewtimetable.this);
col5.setPadding(10,0,0,0);
col5.setText(1:40-3:20PM);
col5.setTextColor(Color.BLUE);
col5.setTextSize(15);
tr.addView(COL5); TextView的COL6 =新的TextView(viewtimetable.this);
col6.setPadding(10,0,0,0);
col6.setText(3:30-5:00);
col6.setTextColor(Color.BLUE);
col6.setTextSize(15);
tr.addView(COL6); tv.addView(TR); 最后查看U电源=新景(viewtimetable.this);
vline.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(U电源); 为(c.moveToFirst();!c.isAfterLast(); c.moveToNext()){ 字符串天= c.getString(c.getColumnIndex(dba.KEY_DAY)); 字符串SLOT1 = c.getString(c.getColumnIndex(7:30-9:10AM));
字符串SLOT2 = c.getString(c.getColumnIndex(9:20-11:00AM));
3号槽位的String = c.getString(c.getColumnIndex(11:10-12:50PM));
串时隙4 = c.getString(c.getColumnIndex(1:40-3:20PM));
字符串slot5 = c.getString(c.getColumnIndex(3:30-5:00)); 的TableRow TR1 =新的TableRow(viewtimetable.this); tr1.setLayoutParams(新的LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)); TextView的B =新的TextView(viewtimetable.this); b.setText(天);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr1.addView(二);
TextView的B1 =新的TextView(viewtimetable.this);
TextView的B2 =新的TextView(viewtimetable.this);
TextView的B3 =新的TextView(viewtimetable.this);
TextView的B4 =新的TextView(viewtimetable.this);
TextView的B5 =新的TextView(viewtimetable.this);
b1.setPadding(10,0,0,0);
b1.setTextSize(15);
b1.setTextColor(Color.RED);
b2.setPadding(10,0,0,0);
b2.setTextColor(Color.RED);
b2.setTextSize(15);
b3.setPadding(10,0,0,0);
b3.setTextColor(Color.RED);
b3.setTextSize(15);
b4.setPadding(10,0,0,0);
b4.setTextColor(Color.RED);
b4.setTextSize(15);
b5.setPadding(10,0,0,0);
b5.setTextColor(Color.RED);
b5.setTextSize(15);
如果(day.equals(星期五))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期一))
{
如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期二))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} }
否则,如果(day.equals(星期三))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} }
否则,如果(day.equals(星期四))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } 否则,如果(day.equals(星期六))
{ 如果(SLOT1!= NULL){
b1.setText(SLOT1);
}
如果(SLOT2!= NULL)
{
b2.setText(SLOT2);
}
如果(3号槽位!= NULL)
{
b3.setText(3号槽位);
}
如果(时隙4!= NULL)
{
b4.setText(时隙4);
}
如果(slot5!= NULL)
{
b5.setText(slot5);
} } tr1.addView(B1);
tr1.addView(B2);
tr1.addView(B3);
tr1.addView(B4);
tr1.addView(B5);
tv.addView(TR1);
我觉得发生了什么事是第一次轮(如果当前行是周五),你有标志= 1,指示创建的列。然而,你有结构是这样的:
而GetNextRow
如果标志= 1
创建COLS,设置标志= 0
其他
连续的过程
万一
循环
在第一次通过,你周五,创建列,然后循环。
在第二次通过你周六和处理的行。等等等等。
您需要取出东西。你也可以把循环之前的创建列的逻辑:那是,如果没有数据可言,你仍然可以用定义的列,并没有数据的屏幕,而不是空白你用在没有得到数据时刻。
干杯 -
I am retrieving my sqlite table data successfully in my android app.However it has some minor problem which i am not able to figure out.
Code Snippet:
int flag=1;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
String day = c.getString(c.getColumnIndex("day"));
String slot1 = c.getString(c.getColumnIndex("7:30-9:10AM"));
String slot2 = c.getString(c.getColumnIndex("9:20-11:00AM"));
String slot3 = c.getString(c.getColumnIndex("11:10-12:50PM"));
String slot4 = c.getString(c.getColumnIndex("1:40-3:20PM"));
String slot5 = c.getString(c.getColumnIndex("3:30-5:00PM"));
TableRow tr=new TableRow(viewtimetable.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
if(flag==1)
{
TextView col1=new TextView(viewtimetable.this);
col1.setText("Day");
col1.setTextColor(Color.BLUE);
col1.setTextSize(15);
tr.addView(col1);
TextView col2=new TextView(viewtimetable.this);
col2.setPadding(10, 0, 0, 0);
col2.setTextSize(15);
col2.setText("7:30-9:10AM");
col2.setTextColor(Color.BLUE);
tr.addView(col2);
TextView col3=new TextView(viewtimetable.this);
col3.setPadding(10, 0, 0, 0);
col3.setText("9:20-11:00AM");
col3.setTextColor(Color.BLUE);
col3.setTextSize(15);
tr.addView(col3);
TextView col4=new TextView(viewtimetable.this);
col4.setPadding(10, 0, 0, 0);
col4.setText("11:10-12:50PM");
col4.setTextColor(Color.BLUE);
col4.setTextSize(15);
tr.addView(col4);
TextView col5=new TextView(viewtimetable.this);
col5.setPadding(10, 0, 0, 0);
col5.setText("1:40-3:20PM");
col5.setTextColor(Color.BLUE);
col5.setTextSize(15);
tr.addView(col5);
TextView col6=new TextView(viewtimetable.this);
col6.setPadding(10, 0, 0, 0);
col6.setText("3:30-5:00PM");
col6.setTextColor(Color.BLUE);
col6.setTextSize(15);
tr.addView(col6);
tv.addView(tr);
final View vline = new View(viewtimetable.this);
vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(vline);
flag=0;
}
else
{
TextView b=new TextView(viewtimetable.this);
//String stime=json_data.getString("day");
b.setText(day);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr.addView(b);
TextView b1=new TextView(viewtimetable.this);
TextView b2=new TextView(viewtimetable.this);
TextView b3=new TextView(viewtimetable.this);
TextView b4=new TextView(viewtimetable.this);
TextView b5=new TextView(viewtimetable.this);
b1.setPadding(10, 0, 0, 0);
b1.setTextSize(15);
b1.setTextColor(Color.RED);
b2.setPadding(10, 0, 0, 0);
b2.setTextColor(Color.RED);
b2.setTextSize(15);
b3.setPadding(10, 0, 0, 0);
b3.setTextColor(Color.RED);
b3.setTextSize(15);
//tr.addView(b3);
b4.setPadding(10, 0, 0, 0);
b4.setTextColor(Color.RED);
b4.setTextSize(15);
//tr.addView(b4);
b5.setPadding(10, 0, 0, 0);
b5.setTextColor(Color.RED);
b5.setTextSize(15);
//tr.addView(b5);
if(day.equals("Monday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Tuesday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Wednesday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Thursday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Friday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Saturday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
tr.addView(b1);
tr.addView(b2);
tr.addView(b3);
tr.addView(b4);
tr.addView(b5);
tv.addView(tr);
Result :
Question :
I wonder why Friday's row is not getting displayed?
P.S:As i have successfully retrieved all the required data except Friday's data hence there is some minor issue with the above code snippet only i guess.
Edit :
The problem is in else block.As the first data is Friday and the else block don't get executed for the first iteration hence the problem arises.
Tried removing else block and it generates exception
specified child already has parent.you must call removeView() on the child's parent first.
Solution :
What i did is inside the loop i created a new Tablerow
and then added views
to that row.
Final Correct Code :
TableLayout tv=(TableLayout) findViewById(R.id.table);
tv.removeAllViewsInLayout();
int flag=1;
TableRow tr=new TableRow(viewtimetable.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView col1=new TextView(viewtimetable.this);
col1.setText("Day");
col1.setTextColor(Color.BLUE);
col1.setTextSize(15);
tr.addView(col1);
TextView col2=new TextView(viewtimetable.this);
col2.setPadding(10, 0, 0, 0);
col2.setTextSize(15);
col2.setText("7:30-9:10AM");
col2.setTextColor(Color.BLUE);
tr.addView(col2);
TextView col3=new TextView(viewtimetable.this);
col3.setPadding(10, 0, 0, 0);
col3.setText("9:20-11:00AM");
col3.setTextColor(Color.BLUE);
col3.setTextSize(15);
tr.addView(col3);
TextView col4=new TextView(viewtimetable.this);
col4.setPadding(10, 0, 0, 0);
col4.setText("11:10-12:50PM");
col4.setTextColor(Color.BLUE);
col4.setTextSize(15);
tr.addView(col4);
TextView col5=new TextView(viewtimetable.this);
col5.setPadding(10, 0, 0, 0);
col5.setText("1:40-3:20PM");
col5.setTextColor(Color.BLUE);
col5.setTextSize(15);
tr.addView(col5);
TextView col6=new TextView(viewtimetable.this);
col6.setPadding(10, 0, 0, 0);
col6.setText("3:30-5:00PM");
col6.setTextColor(Color.BLUE);
col6.setTextSize(15);
tr.addView(col6);
tv.addView(tr);
final View vline = new View(viewtimetable.this);
vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(vline);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
String day = c.getString(c.getColumnIndex(dba.KEY_DAY));
String slot1 = c.getString(c.getColumnIndex("7:30-9:10AM"));
String slot2 = c.getString(c.getColumnIndex("9:20-11:00AM"));
String slot3 = c.getString(c.getColumnIndex("11:10-12:50PM"));
String slot4 = c.getString(c.getColumnIndex("1:40-3:20PM"));
String slot5 = c.getString(c.getColumnIndex("3:30-5:00PM"));
TableRow tr1=new TableRow(viewtimetable.this);
tr1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView b=new TextView(viewtimetable.this);
b.setText(day);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr1.addView(b);
TextView b1=new TextView(viewtimetable.this);
TextView b2=new TextView(viewtimetable.this);
TextView b3=new TextView(viewtimetable.this);
TextView b4=new TextView(viewtimetable.this);
TextView b5=new TextView(viewtimetable.this);
b1.setPadding(10, 0, 0, 0);
b1.setTextSize(15);
b1.setTextColor(Color.RED);
b2.setPadding(10, 0, 0, 0);
b2.setTextColor(Color.RED);
b2.setTextSize(15);
b3.setPadding(10, 0, 0, 0);
b3.setTextColor(Color.RED);
b3.setTextSize(15);
b4.setPadding(10, 0, 0, 0);
b4.setTextColor(Color.RED);
b4.setTextSize(15);
b5.setPadding(10, 0, 0, 0);
b5.setTextColor(Color.RED);
b5.setTextSize(15);
if(day.equals("Friday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Monday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Tuesday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Wednesday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Thursday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
else if(day.equals("Saturday"))
{
if(slot1 != null){
b1.setText(slot1);
}
if(slot2 != null)
{
b2.setText(slot2);
}
if(slot3 != null)
{
b3.setText(slot3);
}
if(slot4 != null)
{
b4.setText(slot4);
}
if(slot5 != null)
{
b5.setText(slot5);
}
}
tr1.addView(b1);
tr1.addView(b2);
tr1.addView(b3);
tr1.addView(b4);
tr1.addView(b5);
tv.addView(tr1);
I think what's happening is that the first time round (when the current row is Friday) you have flag = 1 to signal creating the columns. However the structure you have is like this:
while GetNextRow
if flag = 1
create cols, set flag = 0
else
process row
endif
loop
On the first time through, you get Friday, create the columns and then loop. On the second time through you get Saturday and process the row. Etc etc.
You need to take out the else. You could also put the create columns logic before the loop: that was if there is no data at all, you'd still get a screen with the columns defined and no data, rather than the blank you'd get with no data at the moment.
Cheers -
这篇关于在获取Android应用SQLite表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!