0

我正在从事与智力竞赛相关的项目。在项目中,我希望在同一个按钮上单击两个事件,例如当用户单击按钮(答案选项)时,它会将他检索到另一个问题(来自同一个数组列表),同时将单击的答案保存到数据库中。提前致谢 !

我正在做这样的事情..

public class QuizeActivity extends Activity implements
        android.view.View.OnClickListener {
    private List<String> Questionlist = new ArrayList<String>();
    private List<String> FirstOptionlist = new ArrayList<String>();
    private List<String> SecondOptionlist = new ArrayList<String>();
    private List<String> ThirdOptionlist = new ArrayList<String>();
    private List<String> FourthOtionlist = new ArrayList<String>();
    private List<String> RightOtionlist = new ArrayList<String>();
    DBAdapter db = new DBAdapter(this);
    private String question, opt_one, opt_two, opt_three, opt_four, roght;
    private Button op1_btn, op2_btn, op3_btn, op4_btn;
    private TextView quest;
    private int count = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        quest = (TextView) findViewById(R.id.ques_txt);
        op1_btn = (Button) findViewById(R.id.optOne_btn);
        op2_btn = (Button) findViewById(R.id.optSec_btn);
        op3_btn = (Button) findViewById(R.id.optThrd_btn);
        op4_btn = (Button) findViewById(R.id.optFrt_btn);
        op1_btn.setOnClickListener(this);
        op2_btn.setOnClickListener(this);
        op3_btn.setOnClickListener(this);
        op4_btn.setOnClickListener(this);

        Questionlist.clear();
        FirstOptionlist.clear();
        SecondOptionlist.clear();
        ThirdOptionlist.clear();
        FourthOtionlist.clear();
        RightOtionlist.clear();

        // ---get all titles---
        try {
            db.open();
            Cursor c = db.getAllTitles();
            if (c.moveToFirst()) {
                do {
                    DisplayTitle(c);
                } while (c.moveToNext());
            }
            c.close();
            db.close();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        on_ButtonClick();

    }

    private void DisplayTitle(Cursor c) {
        // TODO Auto-generated method stub
        Questionlist.add(c.getString(1));
        FirstOptionlist.add(c.getString(2));
        SecondOptionlist.add(c.getString(3));
        ThirdOptionlist.add(c.getString(4));
        FourthOtionlist.add(c.getString(5));
        RightOtionlist.add(c.getString(6));
    }

    private void on_ButtonClick() {
                quest.setText(Questionlist.get(count));
                op1_btn.setText(FirstOptionlist.get(count));
                op2_btn.setText(SecondOptionlist.get(count));
                op3_btn.setText(ThirdOptionlist.get(count));
                op4_btn.setText(FourthOtionlist.get(count));

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == op1_btn) {

        }

        if (v == op2_btn) {
            count++;
        }
        if (v == op3_btn) {
            count++;
        }
        if (v == op4_btn) {
            count++;
        }

    }

}
4

0 回答 0