让 phone 调用保持触摸字符串

make phone call on keeping touch an string

我有一个不知道如何搜索的问题,它很难搜索。 我有一个简单的 GridView,它有 3 列,第一列名为名称,第二列名为 phone 编号,最后命名为状态。 第二列是 phone 个我想在一个 ArrayList 中显示的数字。 (全部在字符串中) 显示正常, 但我希望当用户保持触摸第二列,或单击它或任何其他内容时,调用此 phone 编号的 android 对话框应用程序。 我该怎么做?

我对此搜索的内容显示了调用方法和 类。

我这里的简单代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    gridView = (GridView) findViewById(R.id.gridView);
    arrayList = new ArrayList<String>();
    arrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_gallery_item, arrayList);

    ConnectionHelper connectionHelper = new ConnectionHelper();
    CallableStatement callableStatement;

    try {
        callableStatement =  connectionHelper.getConnection().prepareCall("{call getData}");
        callableStatement.execute();
        ResultSet resultSet =  callableStatement.getResultSet();
        if(resultSet.next())
        {
            String name ;
            int p;
            String status;
            String phone;
            name = resultSet.getString("Name"); // get name from SP
            p = resultSet.getInt("PhoneNumber"); // get the int of phoneNumber
            status = resultSet.getString("Status");
            phone = String.valueOf(p); // cast integer to string
            arrayList.add(name);
            arrayList.add(phone);
            arrayList.add(status);
            arrayAdapter.getItemViewType(R.id.gridView);
            gridView.setAdapter(arrayAdapter);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

您需要创建一个 "intent" 来进行 phone 调用:

Intent phoneCallIntent = new Intent( Intent.ACTION_CALL );          
phoneCallIntent.setData( Uri.parse( "tel:" + phone ) );          
startActivity( phoneCallIntent );

然后您可以将该代码放入该列的 onClick 事件中。

有关更多信息,您可以搜索类似内容:"android intent phone call"

首先,您需要将 OnItemClickListener 添加到您的网格视图。当您的应用程序上的网格项目 clicked/touched 时,这将启用点击事件。

gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
  //Your Working will be done here.
}
});

现在你说你的 phone 号码在第二位,所以添加这个 :-

所以,

if(position == 1)
{
Intent phoneCallIntent = new Intent( Intent.ACTION_CALL );          
phoneCallIntent.setData( Uri.parse( "tel:" + phone ) );          
startActivity( phoneCallIntent );
}

希望对您有所帮助。

我认为您只想在第 2 列上获取点击事件。为此,您需要在网格视图上设置点击监听器,然后检查位置。 尝试类似下面的代码。

gridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            if(position%3 ==1){
                try {
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:"+"your mobile no"));
                    startActivity(callIntent);
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(context,
                            "There are no calling clients installed.",
                            Toast.LENGTH_SHORT).show();
                }
            }

    }
});