android - 如何在 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 方法添加到如何使用它来实现。
解决方案
如果我理解正确,那么您想知道如何通过号码拨打电话吗?
此代码用于您的项目,它将打开一个带有电话号码的呼叫应用程序:
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);
推荐阅读
- graph - 通过命令行可重现地自动布局 BPMN 工作流?
- ios - SwiftUI Disable specific tabItem selection in a TabView?
- android - 如何在谷歌控制台中排除除手机之外的所有设备
- c# - 如何在linq to sql中使用orderby和partition by获取第一行
- python - Malformed Lambda proxy response - Python
- python - Reading a text file in discord.py rewrite
- excel - Run macro on change within target range | Change (ByVal Target As Range)
- java - 如何解决SqlIntegrityConstraintViolationException?
- google-cloud-platform - Whoami doesn't change in GCP after I run gcloud auth login
- java - Spring MVC 中如何使用 IoC 和 DI