如何在单击ListView时打开拨号器

时间:2015-03-17 07:18:02

标签: android

我有一个应用程序,其中列表视图位于该列表视图编号中,按钮就在那里,我希望该按钮点击编号进入拨号屏幕... 请建议

3 个答案:

答案 0 :(得分:2)

我认为你要求通话功能,点击按钮点击下面的代码,

Intent intent = new Intent(Intent.ACTION_DIAL); 
intent.setData(Uri.parse("tel:" + "2356894745"));
startActivity(intent); 

答案 1 :(得分:1)

你可以这样试试:

phone.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

           Intent intent = new Intent(Intent.ACTION_DIAL); 
           intent.setData(Uri.parse("tel:" + "12345"));
           startActivity(intent); 

        }
    });

'tel:'前缀是必需的,否则将抛出以下异常: java.lang.IllegalStateException:无法执行活动的方法。

Action_Dial不需要任何权限。

如果您想立即拨打该号码,可以使用操作Intent.ACTION_CALL。在这种情况下,您必须在AndroidManifest.xml中添加以下权限:

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

答案 2 :(得分:0)

public class Help_Ambulance扩展了ListActivity {

@Override
public void onCreate(Bundle abc){
    //super.onCreate(savedInstanceState);

    super.onCreate(abc);
    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> item = new HashMap<String, String>();
    HashMap<String, String> item2 = new HashMap<String, String>();
    HashMap<String, String> item3 = new HashMap<String, String>();
    HashMap<String, String> item4 = new HashMap<String, String>();
    HashMap<String, String> item5 = new HashMap<String, String>();
    HashMap<String, String> item6 = new HashMap<String, String>();
    HashMap<String, String> item7 = new HashMap<String, String>();
    HashMap<String, String> item8 = new HashMap<String, String>();
    HashMap<String, String> item9 = new HashMap<String, String>();
    HashMap<String, String> item10 = new HashMap<String, String>();

    item.put("name", "Pune Ambulance");
    item.put("number", "101");
    item.put("address", "Pune City");

    item2.put("name", "Jeevan Jyoti Services");
    item2.put("number", "02067288011");
    item2.put("address", "Nali Road, Hadapsar");

    item3.put("name", "Bharat Ambulance Services");
    item3.put("number", "02066823158");
    item3.put("address", "Hospital Vallabh Nagar, Pimpri");        

    item4.put("name", "Lokmangal Ambulance Services");
    item4.put("number", "02040422273");
    item4.put("address", "Hospital, Deccan Gymkhana");        

    item5.put("name", "Deendayal Memorial Hospital");
    item5.put("number", "02025652497");
    item5.put("address", "Paduka, Fergusson College Road");        

    item6.put("name", "Ruby Hall Clinic");
    item6.put("number", "02026121099");
    item6.put("address", "Bund Garden Road, Pune");        

    item7.put("name", "Sahyadri Hospital");
    item7.put("number", "02025403000");
    item7.put("address", "");        

    item8.put("name", "Deenanath Mangeshkar Hospital Ambulance Services");
    item8.put("number", "02040151000");
    item8.put("address", "Erandwane");        

    item9.put("name", "Jehangir Hospital");
    item9.put("number", "02026121066");
    item9.put("address", "Pune Station, Pune");    

    item10.put("name", "Kolumbus Ambulance And Healthcare");
    item10.put("number", "02066826189");
    item10.put("address", "Shirole Road, Shivaji Nagar");    

    list.add(item);
    list.add(item2);
    list.add(item3);
    list.add(item4);
    list.add(item5);
    list.add(item6);
    list.add(item7);
    list.add(item8);
    list.add(item9);
    list.add(item10);


    String[] columns = new String[] { "name", "number", "address" };
    int[] renderTo = new int[] { R.id.name, R.id.number, R.id.address };

    ListAdapter listAdapter = new SimpleAdapter(this, list,   R.layout.help_ambulance_row, columns, renderTo);

    setListAdapter(listAdapter);
}       

}