1

我想要一个对话框来监听短按长按(当用户将手指放在一个项目上并通过播放音频文件的预览对其做出反应时,而不关闭 DialogInterface(有点为用户)。

检查DialogInterface 类的 API 后,我发现它只提供了一个 OnClickListener。是否有可能让 DialogInterface 对象同时监听两者

这是代码:

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();
}

}

4

1 回答 1

0

您可以在您的setView上使用AlertDialog.Builder,然后将您想要的侦听器添加到您的自定义视图中。

于 2013-11-14T21:10:33.957 回答