Java 无法从ListView项目中检索意向的地址和电话号码

Java 无法从ListView项目中检索意向的地址和电话号码,java,android,listview,android-intent,arraylist,Java,Android,Listview,Android Intent,Arraylist,我是一名android初学者,正在为我的Udacity课程开发一款应用程序。我在ListView项中放置了两个按钮—一个用于打开地图,另一个用于调用。为了让它们工作,我试图从列表中的当前对象中检索地址和电话号码,但它不工作,即使地图和电话应用程序被打开,它只显示我的位置,而不是对象位置和随机电话号码 这是我的Adapdter类中的代码: public class LocationAdapter extends ArrayAdapter<Location>{ private Strin

我是一名android初学者,正在为我的Udacity课程开发一款应用程序。我在ListView项中放置了两个按钮—一个用于打开地图,另一个用于调用。为了让它们工作,我试图从列表中的当前对象中检索地址和电话号码,但它不工作,即使地图和电话应用程序被打开,它只显示我的位置,而不是对象位置和随机电话号码

这是我的Adapdter类中的代码:

public class LocationAdapter extends ArrayAdapter<Location>{
private String address;
//create custom constructor for LocationAdapter
public LocationAdapter (Activity context, ArrayList<Location> locations){
    super (context, 0, locations);
}
//Provide a View (ListView) for adapter
//@param position - the position of the item in the adapter
//@param convertView - the old view to reuse, if available
//@param parent - the parent view this view will be attached to

@Override
public View getView (int position, View convertView, ViewGroup parent){
    View listItemView = convertView;
    if (listItemView==null){
        listItemView = 
LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }
//Get Location object from this position on the list
    final Location currentLocation = getItem(position);

    //Set onClickListener on Map Button and use an Intent in onClick method 
to open location on map

    final ImageButton mapButton = (ImageButton) 
listItemView.findViewById(R.id.map_button);
    mapButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String address 
 =Integer.toString(currentLocation.getLocationAddressString());
            Intent openMap = new Intent(Intent.ACTION_VIEW);
            openMap.setData(Uri.parse("geo:"+ address));
            getContext().startActivity(openMap);

        }
    });
     //Set onClickListener on Call Button and use an Intent in onClick method 
to open a dialer
    final ImageButton callButton = (ImageButton) 
listItemView.findViewById(R.id.call_button);
    callButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String number 
=Integer.toString(currentLocation.getLocationPhoneNumberString());
            Intent makeCall = new Intent (Intent.ACTION_DIAL);
            makeCall.setData(Uri.parse("tel:"+number));
            getContext().startActivity(makeCall);
        }
    });


    //Find ImageView and set an Image of the current Location object
    ImageView locationImage =(ImageView) 
listItemView.findViewById(R.id.image);
    locationImage.setImageResource(currentLocation.getImageResourceId());

    //Find Location Name TextView and set Name of the current Location object
    TextView locationName =(TextView) listItemView.findViewById(R.id.name);
    locationName.setText(currentLocation.getLocationNameString());

    //Find Location Description TextView and set Description of the current 
Location object
    TextView locationDescription = (TextView) 
listItemView.findViewById(R.id.description);
    
locationDescription.setText(currentLocation.getLocationDescriptionString());

    return listItemView;
}
 }

解决了的
因此,问题在于将LocationAddress存储为自定义类中的整数,而不是将其存储为字符串。

认为这可能与如何在这一行上创建地址URI有关:

openMap.setData(Uri.parse("geo:"+ address));
基本上,这将输出一个addressUri,看起来像:

geo:123 Sesame St
但是,查看中的示例需要进行一些更改:

1) 使用地址时,该纬度/经度应设置为0,0
2) 实际上,您必须指定Uri的
?q=
部分

因此,我认为如果您将前面提到的行更改为这一行,它应该可以工作:

openMap.setData(Uri.parse("geo:0,0?q="+ address));

嗨,伙计们,我试着做了你们建议的改变,但仍然不起作用。
openMap.setData(Uri.parse("geo:0,0?q="+ address));