Android:Button没有突然响应

时间:2013-01-18 07:28:44

标签: android database button onclicklistener

我的按钮没有突然响应......昨天它工作得非常好,当我回到电脑后它再也无法工作了......

当我点击按钮cmd_forward时没有任何反应......没有logcat在设备上没有反应......

Oncreate的一部分:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.question);
    _id = getIntent().getIntExtra("ID", 1);
    Log.v("ID:", ""+_id);
    filldata();


    Button cmd_forward = (Button) findViewById(R.id.cmd_forward);
    cmd_forward.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {    
            if(_id == 9){
                Log.v("TRUE", "TRUE");
                int min = 1;
                int max = 107;

                Random r = new Random();
                int random = r.nextInt(max - min + 1) + min;

                c = db.rawQuery("SELECT question, answer FROM tbl_questions"+
                        " where _id =='"+random+"'", null);

                if (c != null ) {
                    if  (c.moveToFirst()) {
                              question = c.getString(c.getColumnIndex("question"));
                              answer = c.getString(c.getColumnIndex("answer"));                   
                              TextView tv_question = (TextView) findViewById(R.id.txt_question);                      

                              tv_question.setText(question);
                    }
               }
            } else {


            if(c.moveToNext()){
              question = c.getString(c.getColumnIndex("question"));
              answer = c.getString(c.getColumnIndex("answer"));                   

              TextView tv_question = (TextView) findViewById(R.id.txt_question);                      

              tv_question.setText(question);
            }
            }
        }
    });

filldata():

    public void filldata(){

    db = SQLiteDatabase.openDatabase("/data/data/spicysoftware.abugrundwissen/databases/questions", null,
            SQLiteDatabase.OPEN_READWRITE);

    if(_id == 9){

        int min = 1;
        int max = 107;

        Random r = new Random();
        _id= r.nextInt(max - min + 1) + min;

        c = db.rawQuery("SELECT question, answer, favourite FROM tbl_questions"+
                " where _id =='"+_id+"'", null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                      question = c.getString(c.getColumnIndex("question"));
                      answer = c.getString(c.getColumnIndex("answer"));        
                      favourite = c.getInt(c.getColumnIndex("favourite"));
                      TextView tv_question = (TextView) findViewById(R.id.txt_question);                      

                          tv_question.setText(question);


            }
       }

    } else {
    c = db.rawQuery("SELECT question, answer, favourite FROM tbl_questions"+
            " where rubrik =='"+_id+"'", null);

    if (c != null ) {
        if  (c.moveToFirst()) {
                  question = c.getString(c.getColumnIndex("question"));
                  answer = c.getString(c.getColumnIndex("answer"));    
                  favourite = c.getInt(c.getColumnIndex("favourite"));
                  TextView tv_question = (TextView) findViewById(R.id.txt_question);                      

                      tv_question.setText(question);

        }
   }

}

}

logcat的:

01-18 07:19:07.015: D/dalvikvm(617): GC_FOR_ALLOC freed 68K, 5% free 6554K/6855K, paused 29ms, total 30ms
01-18 07:19:07.095: D/dalvikvm(617): GC_FOR_ALLOC freed 2K, 6% free 6810K/7175K, paused 30ms, total 31ms
01-18 07:19:07.095: I/dalvikvm-heap(617): Grow heap (frag case) to 6.946MB for 262160-byte allocation
01-18 07:19:07.175: D/dalvikvm(617): GC_FOR_ALLOC freed <1K, 6% free 7066K/7495K, paused 30ms, total 30ms
01-18 07:19:07.185: V/ID:(617): 9
01-18 07:19:10.855: I/Choreographer(617): Skipped 34 frames!  The application may be doing too much work on its main thread.

1 个答案:

答案 0 :(得分:0)

问题是,我在filldata()中给了“_id”;另一个价值。所以它不是9!