Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 仅适用于onTouch事件的对话框_Android - Fatal编程技术网

Android 仅适用于onTouch事件的对话框

Android 仅适用于onTouch事件的对话框,android,Android,我有一个条形码阅读器,它的工作原理类似于键盘,当读取条形码时,它会发送按键并以enter结束 在我的拣货应用程序中,我会显示一个alertDialog,以确认在读取物品条形码后读取的数量,但如果我在alertDialog显示时读取了另一个条形码,我的应用程序会继续捕获输入键。。。数字键聚焦于“我不知道为什么”的“接受”按钮和“输入”“接受并关闭警报”对话框 是否可以只允许手指触摸来确认alertDialog 编辑: 这是我的alertdialog代码: public void dialogCan

我有一个条形码阅读器,它的工作原理类似于键盘,当读取条形码时,它会发送按键并以enter结束

在我的拣货应用程序中,我会显示一个alertDialog,以确认在读取物品条形码后读取的数量,但如果我在alertDialog显示时读取了另一个条形码,我的应用程序会继续捕获输入键。。。数字键聚焦于“我不知道为什么”的“接受”按钮和“输入”“接受并关闭警报”对话框

是否可以只允许手指触摸来确认alertDialog

编辑: 这是我的alertdialog代码:

public void dialogCantidad(String cantidad, String producto){                                                         
   TextInputEditText focuss = findViewById(R.id.lectura);                                                            
   focuss.clearFocus();                                                                                              

   AlertDialog.Builder builder = new AlertDialog.Builder(activity_detalle.this);                                     
   DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {                     
       @Override                                                                                                     
       public void onClick(DialogInterface dialog, int which) {                                                      
           switch (which){                                                                                           
               case DialogInterface.BUTTON_POSITIVE:                                                                 
                       focuss.requestFocus();                                                                        
                break;                                                                                               

               case DialogInterface.BUTTON_NEGATIVE:                                                                 
                   //No button clicked                                                                               
                   break;                                                                                            
           }                                                                                                         
       }                                                                                                             
   };                                                                                                                

   builder.setMessage(cantidad+" unidades. "+producto).setPositiveButton("Lo tengo, loco", dialogClickListener);     
   builder.setCancelable(false);                                                                                     
   AlertDialog theDialog = builder.create();                                                                         
   theDialog.show();                                                                                                 
   TextView textView = theDialog.findViewById(android.R.id.message);                                                 
   textView.setTextSize(60);}
多亏了我女朋友和我的帮助,你让我产生了用view.ontouch创建自定义对话框的想法

这是创建仅适用于onTouch事件的对话框的代码

XML布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@color/colorPrimary">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            app:srcCompat="@android:drawable/ic_dialog_alert" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FDFDFD"
        android:orientation="vertical"
        android:padding="16dp">

        <TextView
            android:id="@+id/cantidad"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:textSize="50sp" />

        <TextView
            android:id="@+id/producto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text=""
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textSize="36sp" />

        <Button
            android:id="@+id/buttonOk"
            android:layout_width="291dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:text="Lo tengo, loco"
            android:textColor="@color/colorPrimary"
            android:textSize="30sp" />

    </LinearLayout>

</LinearLayout>
阶级

还有我要调用的函数

 public void dialogCantidad(String cantidad, String producto){
    TextInputEditText focuss = findViewById(R.id.lectura);
    focuss.clearFocus();

    CustomDialogClass cdd = new CustomDialogClass(activity_detalle.this, cantidad, producto);
    cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    cdd.setCancelable(false);
    cdd.show();

    Window window = cdd.getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}

android中的对话框是异步的。对话框出现后,代码在后台继续运行。您需要为对话框打开时设置某种变量,当该变量为真时,扫描仪将关闭。我理解,但如果我关闭蓝牙或设备则是浪费时间。蓝牙配对时间太长。是否可以只允许触摸操作并拒绝所有外部设备输入?好的,我理解。您正在使用硬件扫描仪。可以阻止按键。您的选项受stock对话框的限制,您需要在对话框中使用自定义布局,并且在将事件附加到按钮时,仅附加ontouchlistener事件。这将忽略键盘按下。默认的是使用onclick,并对按键做出响应,同时触摸两个按键。谢谢你,John。我认为这是一个完美的解决方案,但在我的构建器中,我声明.setPositiveButton只接受onClick侦听器。我用我的代码编辑了主要帖子。
public class CustomDialogClass extends Dialog implements android.view.View.OnTouchListener {

public Activity c;
public Dialog d;
public Button yes, no;
public String cantidad, producto;

public CustomDialogClass(Activity a, String cantidad, String producto) {
    super(a);
    // TODO Auto-generated constructor stub
    this.c = a;
    this.cantidad = cantidad;
    this.producto = producto;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.custom_dialog);
    yes = (Button) findViewById(R.id.buttonOk);
    yes.setOnTouchListener(this);
    TextView txtcantidad = findViewById(R.id.cantidad);
    TextView txtproducto = findViewById(R.id.producto);

    txtcantidad.setText(this.cantidad+" unidades");
    txtproducto.setText(this.producto);

}

@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
    switch (v.getId()) {
        case R.id.buttonOk:
            dismiss();
            break;
        default:
            break;
    }
    dismiss();

    return false;
}}
 public void dialogCantidad(String cantidad, String producto){
    TextInputEditText focuss = findViewById(R.id.lectura);
    focuss.clearFocus();

    CustomDialogClass cdd = new CustomDialogClass(activity_detalle.this, cantidad, producto);
    cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    cdd.setCancelable(false);
    cdd.show();

    Window window = cdd.getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}