首页 > 解决方案 > 如何在 setOnItemLongClickListener 中实现联系人呼叫按钮?

问题描述

我想在我的应用程序中实现一个呼叫号码按钮,我该怎么做?

mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long l) {

        //Alert dialog to display options of update and delete

        final CharSequence [] items = {"Update","Delete","Call"};
        AlertDialog.Builder dialog = new AlertDialog.Builder(RecordListActivity.this);

        dialog.setTitle("Choose an Action");

        dialog.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if(i == 0){
                    //update
                    Cursor c = MainActivity.mSQLiteHelper.getData("SELECT id FROM RECORD");
                    ArrayList<Integer> arrID = new ArrayList<Integer>();
                    while(c.moveToNext() ){
                        arrID.add(c.getInt(0));
                    }
                    //Show update Dialog
                    showDialogUpdate(RecordListActivity.this,arrID.get(position));
                }
                if(i==1){
                        //delete
                    Cursor c = MainActivity.mSQLiteHelper.getData("SELECT id FROM RECORD");
                    ArrayList<Integer> arrID = new ArrayList<Integer>();

                    while(c.moveToNext()){
                        arrID.add(c.getInt(0));
                    }
                    showDialogDelete(arrID.get(position));
                }
                 if(i==3){
               //Call Method, I don't know how to do that, cause I already use a Model, I don't know how to do that.



          }

            }
        });
        dialog.show();
        return true;
    }
});

我是 Android 新手,如何在 setOnItemLongClickListener() 中进行联系电话。从顶部我将 setOnItemLongClickListener 方法添加到如何使用它来实现。

标签: androidandroid-studioandroid-phone-call

解决方案


如果我理解正确,那么您想知道如何通过号码拨打电话吗?

此代码用于您的项目,它将打开一个带有电话号码的呼叫应用程序:

TextView tvPhone = view.findViewById(R.id.textphone);
String phone = tvPhone.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phone));
view.getContext().startActivity(intent);

官方文档


推荐阅读