如何调用 ListView 中的按钮单击?

How to make a call on button click in a ListView?

我在 CustomAdapter class 的 getView() 方法中完成了以下代码。如果我尝试简单地显示 Toast,则会出现 Toast,但如果我执行以下代码进行调用,应用程序就会崩溃。我在这里做错了什么?

                call.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + phone.getText().toString()));
                    context.startActivity(callIntent);
                }
            });

并且堆栈跟踪显示此错误:

AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hammad.contactme, PID: 26713 android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

尝试在 AndroidManifest 中添加正确的调用权限

<uses-permission android:name="android.permission.CALL_PHONE" />

如果您 运行 使用 android 6.0 或更高版本,您也应该在运行时获得此权限

getting runtime permission