如何点击ListView项目,拨打/呼叫,查看,'未指定的号码,位置或网站?''

时间:2015-03-30 21:51:59

标签: android listview

首先,我在下面的课程中创建了以下字段:

public class AutoMobil {

// Note that this class applies to both the car hire companies and car accessory dealers and car-maintenance shops, Information Should be adjusted to suit the all the companies, dealers and shops as mentioned above.


    private int autoMobiliconId;
    private String autoMobilPhoneNumber;
    private String autoMobilLocation;
    private String autoMobilWebsite;

    public AutoMobil(String autoMobilLocation, int autoMobiliconId, String autoMobilPhoneNumber, String autoMobilWebsite) {
    super();        
    this.autoMobilLocation = autoMobilLocation;
    this.autoMobiliconId = autoMobiliconId;
    this.autoMobilPhoneNumber = autoMobilPhoneNumber;
    this.autoMobilWebsite = autoMobilWebsite;

}


    public String getAutoMobilLocation() {
        return autoMobilLocation;

    }

    public int getAutoMobiliconId() {
        return autoMobiliconId;

    }

    public String getAutoMobilPhoneNumber() {
        return autoMobilPhoneNumber;

    }


    public String getAutoMobilWebsite() {
        return autoMobilWebsite;

    }

}

然后我填写了我的列表如下:

 private void populateAutoMobilList() {

    myAutoMobil.add(new AutoMobil("http://maps.google.com/maps?q=38.87676,-77.03653(Label Point)",R.drawable.g,"tel:0775269482", "http://www.toyota.com" ));`
    myAutoMobil.add(new AutoMobil("http://maps.google.com/maps?q=33.87676,-79.12366(Label Point)", R.drawable.gridwebsite,"tel:0786059016", "http://www.mandelamotors.com"));
    myAutoMobil.add(new AutoMobil( "http://maps.google.com/maps?q=38.87676,-77.03653(Label Point)", R.drawable.gridwebsite, "tel:0705721453", "http://www.hankooktires.com"));

    }

使用如下所示的arrayAdapter填充listView后。

 private void populateListView() {
    ArrayAdapter<AutoMobil> adapter = new MyListAdapter();
    ListView list = (ListView) findViewById(R.id.listViewRestaurantsDiscounts);
    list.setAdapter(adapter);
}

private class MyListAdapter extends ArrayAdapter<AutoMobil> {
    public MyListAdapter() {
        super(FifthActivity.this,R.layout.travel_view, myAutoMobil);

}

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View travelView = convertView;
        if (travelView == null) {
            travelView = getLayoutInflater().inflate(R.layout.travel_view, parent, false);
        }

        AutoMobil currentAutoMobil = myAutoMobil.get(position);

        ImageView imageView = (ImageView)travelView.findViewById(R.id.imageViewTravel);
        imageView.setImageResource(currentAutoMobil.getAutoMobiliconId());

        return travelView;
    }

问题:如何拨打未指定的号码&#39;&#39;在我的填充列表中,或访问未指定的网站&#39;&#39;或者查看未指定的位置&#39;&#39;在地图上,如果我的代码如上所示?

1 个答案:

答案 0 :(得分:0)

访问页面:

public void visitPage(String url){
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
}

拨打电话号码:

public void dialNumber(String number){
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" +number));
    startActivity(intent);
}

清单许可:

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

要打开谷歌地图,您应该调用visitPage,这将打开一个“选择应用程序:谷歌地图,Chrome,浏览器等”的对话框。