DialogInterface与长按一下监听器?

时间:2013-11-14 20:51:39

标签: android click onclicklistener

我希望有一个对话框,可以听取短长点击(当用户将手指放在某个项目上并通过播放音频文件的预览对其做出反应时,无需关闭DialogInterface(为用户提供一些便利)。

检查DialogInterface class上的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();
}

}

1 个答案:

答案 0 :(得分:0)

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

相关问题