如何知道哪个按钮被“点击”“

时间:2012-05-16 08:05:26

标签: android database events

我有一个包含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();
    }   
    }
 } 
});

2 个答案:

答案 0 :(得分:0)

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

int firstPressedButton = -1;
void settingFirstPressedButton (int buttonPressed)
{
if (firstPressedButton == -1)   //when firstPressedButton = -1 it means no button was pressed
  firstPressedButton = buttonPressed;
}

答案 1 :(得分:0)

public void updateDisplay(View v){
    s1=(String) ((Button)v).getTag();
    ss.add(s1);
    System.out.println("nos are**********"+ss);
}   

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