所以你想检查哪个按钮被点击的布局和相应的过程。
这可以通过两种方式来实现。
1.随着的getId()
XML
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next Layout"
android:id="@+id/Next"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
YourActivity
final Button nxtbtn = (Button) findViewById(R.id.Next);
nxtbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int ID = nxtbtn.getId();
if(ID == R.id.Next) // your R file will have all your id's in the literal form.
{
Log.e(TAG,""+ID);
}
}
});
2. TAG
XML
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next Layout"
android:tag="buttonA"
android:id="@+id/Next"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
在XML只需添加一个标记属性
你的活动
final Button nxtbtn = (Button) findViewById(R.id.Next);
nxtbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Tag = nxtbtn.getTag().toString();
Log.e("TAG", "" + Tag);
if (Tag.equal("ButtonA")){ /* Your code here */}
}
});
希望这可以帮助。
使用'button.getId();' –