-5

我有一个包含 9 个按钮的活动,它提供了一些价值。我想按点击顺序获得该值 - 这怎么可能?这是我的代码:

        public boolean onTouch(View arg0, MotionEvent arg1) {
            // TODO Auto-generated method stub
            s1="1";
            i1.setImageResource(R.drawable.lockk1);
            i1.setBackgroundColor(Color.TRANSPARENT);
           // i1.setBackgroundResource(R.drawable.back);
            return false;
        }
    });       
});


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

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        System.out.println("**********"+s1+s2+s3+s4+s5+s6+s7+s8+s9+"******");
          mydb=LockerActivity.this.openOrCreateDatabase("pattern", MODE_PRIVATE, null); 
            Cursor cr= mydb.rawQuery("SELECT * FROM patterntable", null);
 if (cr.getCount() > 0) {                   
    if(cr.moveToFirst()){
            do 
            {
            pass = cr.getString(cr.getColumnIndex("password"));

            password=s1+s2+s3+s4+s5+s6+s7+s8+s9;
            if(password.equals(pass))
            {   
                Intent i=new Intent(LockerActivity.this,first.class);
                startActivity(i);
            }
            else{
                 Intent i=new Intent(LockerActivity.this,LockerActivity.class);
                 startActivity(i);
                 }        
                }   while (cr.moveToNext());

             cr.close();
             mydb.close();
    }   
    }
 } 
});
4

2 回答 2

0

我不是 Android 程序员,但如果我需要在 iOS 上做同样的事情,我会执行以下操作:

int firstPressedButton = -1;
void settingFirstPressedButton (int buttonPressed)
{
if (firstPressedButton == -1)   //when firstPressedButton = -1 it means no button was pressed
  firstPressedButton = buttonPressed;
}
于 2012-05-16T08:42:35.590 回答
0
public void updateDisplay(View v){
    s1=(String) ((Button)v).getTag();
    ss.add(s1);
    System.out.println("nos are**********"+ss);
}   

为相应的按钮设置一些标签

于 2012-05-21T05:45:19.390 回答