Java 在谷歌眼镜的AlertDialog中,滑动手势不起作用
我在我的应用程序上实现了手势检测,在活动中效果很好 现在,我想做的是能够在AlertDialog中使用这些手势检测。 实际上,我有一个带有取消按钮的活动。当我单击此按钮时,用户必须在AlertDialog中确认其选择,AlertDialog有两个按钮:是和否。但是,在此AlertDialog中,滑动手势不起作用,我无法在是或否之间进行选择,因为它只关注否按钮 我想为此警报对话框实现刷卡手势检测。以下是我所做的:Java 在谷歌眼镜的AlertDialog中,滑动手势不起作用,java,android,google-glass,Java,Android,Google Glass,我在我的应用程序上实现了手势检测,在活动中效果很好 现在,我想做的是能够在AlertDialog中使用这些手势检测。 实际上,我有一个带有取消按钮的活动。当我单击此按钮时,用户必须在AlertDialog中确认其选择,AlertDialog有两个按钮:是和否。但是,在此AlertDialog中,滑动手势不起作用,我无法在是或否之间进行选择,因为它只关注否按钮 我想为此警报对话框实现刷卡手势检测。以下是我所做的: package com.example.recente; import andro
package com.example.recente;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;
public class ChoixUtilisateur extends Activity {
private GestureDetector mGestureDetector;
Button cancelno;
Button cancelyes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGestureDetector = createGestureDetector(this);
setContentView(R.layout.fragment_choix_utilisateur);
Button execute = (Button)findViewById(R.id.execute);
execute.setFocusable(true);
execute.setFocusableInTouchMode(true);///add this line
execute.requestFocus();
}
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetector = new GestureDetector(context);
//Create a base listener for generic gestures
gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
@Override
public boolean onGesture(Gesture gesture) {
Button cancel = (Button)findViewById(R.id.cancel);
AlertDialog.Builder cancelbutton = new AlertDialog.Builder(ChoixUtilisateur.this);
if (gesture == Gesture.TAP) {
// do something on tap
if (cancel.hasFocus()){
// .getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)
cancelbutton.setTitle("Confirm");
cancelbutton.setMessage("Do you really want to proceed ?");
cancelbutton.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int i){
dialog.cancel();
Intent intent = new Intent(ChoixUtilisateur.this,Cancel.class);
startActivity(intent);
finish();
}
});
cancelbutton.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int i){
dialog.cancel();
}
});
cancelbutton.setCancelable(false) ;
cancelbutton.create();
AlertDialog dialog = cancelbutton.create();
cancelno = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
cancelyes = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
cancelbutton.show();
}
else{
}
return true;
} else if (gesture == Gesture.TWO_TAP) {
// do something on two finger tap
return true;
} else if (gesture == Gesture.SWIPE_RIGHT) {
// do something on right (forward) swipe
if(cancelno.hasFocus()){
cancelyes.setFocusable(true);
cancelyes.setFocusableInTouchMode(true);///add this line
cancelyes.requestFocus();
}
else{
cancelno.setFocusable(true);
cancelno.setFocusableInTouchMode(true);///add this line
cancelno.requestFocus();
}
return true;
} else if (gesture == Gesture.SWIPE_LEFT) {
// do something on left (backwards) swipe
if(cancelno.hasFocus()){
cancelyes.setFocusable(true);
cancelyes.setFocusableInTouchMode(true);///add this line
cancelyes.requestFocus();
}
else{
cancelno.setFocusable(true);
cancelno.setFocusableInTouchMode(true);///add this line
cancelno.requestFocus();
}
return true;
}
return false;
}
});
return gestureDetector;
}
}
我不确定使用警报对话框是否是谷歌眼镜的最佳实践,使用标准卡片,或者如果你想要更多的定制,你可以使用简单的活动