我在Android平板电脑中创建动态按钮,我想禁用点击同时按钮,我该怎么做?我希望在平板电脑中禁用多点触控可以在Android平板电脑中禁用多点触控吗?代码如下
if (cevap_sayisi == 5) {
btn1.setText(answer
.get(0));
btn1.setBackgroundResource(R.drawable.stylebutton_iyi);
btn1.setTextSize(28);
btn1.setGravity(Gravity.CENTER);
btn1.setTextColor(Color.BLACK);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(
View v) {
// TODO
// Auto-generated
// method stub
Cevapla(1,
question_id);
}
});
btn2.setText(answer
.get(1));
btn2.setBackgroundResource(R.drawable.stylebutton_orta);
btn2.setTextSize(28);
btn2.setGravity(Gravity.CENTER);
btn2.setTextColor(Color.BLACK);
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(
View v) {
// TODO
// Auto-generated
// method stub
Cevapla(2,
question_id);
}
});
btn3.setText(answer
.get(2));
btn3.setBackgroundResource(R.drawable.stylebutton_kotu);
btn3.setTextSize(28);
btn3.setGravity(Gravity.CENTER);
btn3.setTextColor(Color.BLACK);
btn3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(
View v) {
// TODO
// Auto-generated
// method stub
Cevapla(3,
question_id);
}
});
btn4.setText(answer
.get(3));
btn4.setBackgroundResource(R.drawable.stylebutton_fena);
btn4.setTextSize(28);
btn4.setGravity(Gravity.CENTER);
btn4.setTextColor(Color.BLACK);
btn4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(
View v) {
// TODO
// Auto-generated
// method stub
Cevapla(4,
question_id);
}
});
btn5.setText(answer
.get(4));
btn5.setBackgroundResource(R.drawable.stylebutton_cokiyi);
btn5.setTextSize(28);
btn5.setGravity(Gravity.CENTER);
btn5.setTextColor(Color.BLACK);
btn5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(
View v) {
// TODO
// Auto-generated
// method stub
Cevapla(5,
question_id);
}
});
LinearLayout ll = (LinearLayout) findViewById(R.id.buttonlayout);
ll.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp = new LayoutParams(
new LayoutParams(
320,
120));
ll.addView(btn1, lp);
ll.addView(btn2, lp);
ll.addView(btn3, lp);
ll.addView(btn4, lp);
ll.addView(btn5, lp);
lm.addView(ll);
答案 0 :(得分:1)
btn.setclickable(假); btn.setActivated(假);
答案 1 :(得分:0)
动态创建按钮
按钮myButton = new Button(this); myButton.setText("你好&#34);
LinearLayout ll =(LinearLayout)findViewById(R.id.buttonlayout); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); ll.addView(myButton,lp);
并禁用点击使用此
myButton.setEnabled(假);
要禁用多点触控,请在清单
中使用此功能< uses-feature android:name =" android.hardware.touchscreen.multitouch"机器人:需要="假" />
希望这会有所帮助....
答案 2 :(得分:0)
if (!CommonUtil.isFastDoubleClick()) {
//to do sth
}
CommonUtils.java
private static long lastClickTime;
public static boolean isFastDoubleClick() {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
if ( 0 < timeD && timeD < 500) {
return true;
}
lastClickTime = time;
return false;
}