简体   繁体   English

带有长单击侦听器的DialogInterface?

[英]DialogInterface with a long click listener?

I would like to have a dialog that listens for short and long clicks (when the user holds their finger on an item and react to it by playing a preview of an audio file, without closing the the DialogInterface (sort of providing some convenience to the user). 我希望有一个对话框,它可以监听短暂长时间的单击(当用户将手指放在某个项目上并通过播放音频文件的预览对其做出反应时,无需关闭DialogInterface(为用户提供一些便利)。用户)。

After checking the API on the DialogInterface class , I see that it only offers an OnClickListener. 检查DialogInterface类的API后,我看到它仅提供一个OnClickListener。 Is it possible the make the DialogInterface object listen for both ? 是否可以使DialogInterface对象侦听这两者

Here's the code: 这是代码:

public class SetMetronomeDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Pick a tempo");
    builder.setItems(R.array.tempoArray, new DialogInterface.OnClickListener() {

        // this code works fine since it's from the Android Developer site :)
        public void onClick(DialogInterface dialog, int which) {
               // The 'which' argument contains the index position
               // of the selected item
            Toast.makeText(getActivity(), "" + which, Toast.LENGTH_SHORT).show();               
        }

       // this is my 'dream method', doesn't work of course...
       public void onLongClick(DialogInterface dialog, int which) {

           Toast.makeText(getActivity(), "" + which, Toast.LENGTH_SHORT).show();
       }
    });
    return builder.create();
}

} }

你可以使用的setViewAlertDialog.Builder ,然后你想要的侦听器添加到您的自定义视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM