0

如何获取变量text1text2time在开始时只显示一次,例如标题,因为它们对于特定的数据组具有相同的值,然后在下面显示变量text3,因为该变量具有该特定数据组的值。

写入数据完成text3后,对于该组数据,查询必须开始写入另一组数据,text1text2time的新值text3

这是我的代码:

 public class NapredakActivity extends Activity {  
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.first);
 String var;
 final TextView t = (TextView) findViewById(R.id.textView2);
 Intent intent = getIntent();
 var=intent.getStringExtra("date");
       SQLiteDatabase db = openOrCreateDatabase("Database", MODE_PRIVATE, null);
       String q = "SELECT text1 ,text2, text3, time FROM table WHERE time LIKE '"+var+"'";

       Cursor c = db.rawQuery(q, null);

       if( c.getCount() < 1 ){

           c.close();
           db.close();
           Toast.makeText(NapredakActivity.this, "wrong choice",Toast.LENGTH_LONG).show();

           startActivity(new Intent(this,calendar.class));
       }
       else{
                 String j="";
                                           c.moveToFirst();
                         do {
                          String cm = c.getString(c.getColumnIndex("text1" )); 
                          String cm2 = c.getString(c.getColumnIndex("text2"));            
                          String cm4 = c.getString(c.getColumnIndex("text3"));
                          String cm3 = c.getString(c.getColumnIndex("time" ));

                        j = j+"\n"+cm+cm4+cm2+cm3;  

                          } while (c.moveToNext());

                         t.setText(j);   
                   c.close();
              db.close();        
       }        }    }
4

1 回答 1

0

如果我理解正确,假设您喜欢保持显示 db 内容的方式,即在一个 TextView 中,只需使用这样的标志:

else{
                         String cmOld ="a text that never will be in the BD";
                         boolean flag_newText1Found;
                         String j="";
                         c.moveToFirst();
                         do {
                          String cm = c.getString(c.getColumnIndex("text1" )); 
                          if (cm.equals(cmOld)) 
                             cm = "";
                          else
                             cmOld = cm;
                          String cm2 = c.getString(c.getColumnIndex("text2"));            
                          String cm4 = c.getString(c.getColumnIndex("text3"));
                          String cm3 = c.getString(c.getColumnIndex("time" ));

                        j = j+"\n"+cm+cm4+cm2+cm3;  

                          } while (c.moveToNext());


                         t.setText(j); 
于 2012-06-21T09:34:30.523 回答