Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-单击listview项目时锁定要映射的位置?_Android_Listview_Android Mapview_Android Alertdialog - Fatal编程技术网

Android-单击listview项目时锁定要映射的位置?

Android-单击listview项目时锁定要映射的位置?,android,listview,android-mapview,android-alertdialog,Android,Listview,Android Mapview,Android Alertdialog,我有一个列表视图,其中包含了几家出租车公司。当用户单击出租车名称时,会显示一个警报对话框,要求他们预订、显示地图或取消。我试图实现的是,当用户单击ShowMap时,它从已经设置的字符串数组中获取位置,然后在地图上指向它。我不想让它找到我目前的位置。这可能吗?我已经有了一个mapview设置,目前只指向教程中的随机位置集 以下是我的代码: ListTaxi Class : class Taxi { private String taxiName;

我有一个列表视图,其中包含了几家出租车公司。当用户单击出租车名称时,会显示一个警报对话框,要求他们预订、显示地图或取消。我试图实现的是,当用户单击ShowMap时,它从已经设置的字符串数组中获取位置,然后在地图上指向它。我不想让它找到我目前的位置。这可能吗?我已经有了一个mapview设置,目前只指向教程中的随机位置集

以下是我的代码:

    ListTaxi Class : 

             class Taxi {
    private String taxiName;
    private String taxiAddress;
    private String taxiDist;

    public String getName() {
        return taxiName;
    }

    public void setName(String name) {
        taxiName = name;
    }

    public String getAddress() {
        return taxiAddress;
    }

    public void setAddress(String address) {
        taxiAddress = address;
    }
    public String getDist() {
        return taxiDist;
    }
    public void setDist(String dist){
        taxiDist = dist;
    }
    public Taxi(String name, String address, String dist) {
        taxiName = name;
        taxiAddress = address;
        taxiDist = dist;
    }
}

public class TaxiAdapter extends ArrayAdapter<Taxi> {
    private ArrayList<Taxi> items;
    private TaxiViewHolder taxiHolder;

    private class TaxiViewHolder {
        TextView name;
        TextView address; 
        TextView dist;
    }

    public TaxiAdapter(Context context, int tvResId, ArrayList<Taxi> items) {
        super(context, tvResId, items);
        this.items = items;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.taxi_list_item, null);
            taxiHolder = new TaxiViewHolder();
            taxiHolder.name = (TextView)v.findViewById(R.id.taxi_name);
            taxiHolder.address = (TextView)v.findViewById(R.id.taxi_address);
            taxiHolder.dist = (TextView)v.findViewById(R.id.taxi_dist);
            v.setTag(taxiHolder);
        } else taxiHolder = (TaxiViewHolder)v.getTag(); 

        Taxi taxi = items.get(pos);

        if (taxi != null) {
            taxiHolder.name.setText(taxi.getName());
            taxiHolder.address.setText(taxi.getAddress());
            taxiHolder.dist.setText(taxi.getDist());
        }

        return v;
    }
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listtaxi);

    final String[] taxiNames = getResources().getStringArray(R.array.taxi_name_array);
    final String[] taxiAddresses = getResources().getStringArray(R.array.taxi_address_array);
    final String[] taxiDist = getResources().getStringArray(R.array.taxi_array_dist);
    ArrayList<Taxi> taxiList = new ArrayList<Taxi>();

    for (int i = 0; i < taxiNames.length; i++) {
        taxiList.add(new Taxi(taxiNames[i], taxiAddresses[i], taxiDist[i]));

    }


    setListAdapter(new TaxiAdapter(this, R.layout.taxi_list_item, taxiList));  

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> a, View v, final int position, long id)
        {       

            final int selectedPosition = position;
            AlertDialog.Builder adb=new AlertDialog.Builder(ListTaxi.this); 
             adb.setTitle("Taxi Booking");
             adb.setMessage("You Have Selected: "+taxiNames[selectedPosition]); 
             adb.setPositiveButton("Book", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     Intent intent = new Intent(ListTaxi.this, Booking.class);
                     intent.putExtra("booking",  taxiNames[selectedPosition]);
                     intent.putExtra("address",  taxiAddresses[selectedPosition]);
                     intent.putExtra("distance", taxiDist[selectedPosition]);
                     startActivity(intent);
                 }
             });
             adb.setNeutralButton("Show Map", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     Intent intent = new Intent(ListTaxi.this, Map.class);
                     startActivity(intent);
                 }
             });

             adb.setNegativeButton("Cancel", null); 
             adb.show();
         }
     });     
}
ListTaxi类别:
班车{
私有字符串名称;
专用字符串地址;
私人出租车司机;
公共字符串getName(){
返回出租车名称;
}
公共void集合名(字符串名){
名称=名称;
}
公共字符串getAddress(){
返回地址;
}
公共无效设置地址(字符串地址){
地址=地址;
}
公共字符串getDist(){
返回出租车司机;
}
公共void setDist(字符串dist){
滑行距离=距离;
}
公共出租车(字符串名称、字符串地址、字符串距离){
名称=名称;
地址=地址;
滑行距离=距离;
}
}
公共类出租车适配器扩展阵列适配器{
私有ArrayList项;
私人的士车主;
私家车乘客{
文本视图名称;
文本视图地址;
文本视图区;
}
公共出租车适配器(上下文、int TVRIST、ArrayList项){
超级(上下文、TVRID、项目);
这个项目=项目;
}
@凌驾
公共视图getView(int pos、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutInflater vi=(LayoutInflater)getSystemService(布局\充气机\服务);
v=vi.充气(R.布局.滑行列表项目,空);
出租车持有者=新出租车视图持有者();
taxiHolder.name=(TextView)v.findViewById(R.id.taxi\u name);
taxiHolder.address=(TextView)v.findViewById(R.id.taxi\u地址);
taxiHolder.dist=(TextView)v.findViewById(R.id.taxi\u dist);
v、 setTag(出租车乘客);
}else taxiHolder=(TaxiViewHolder)v.getTag();
出租车=物品。获取(pos);
如果(滑行!=null){
taxiHolder.name.setText(taxi.getName());
taxiHolder.address.setText(taxi.getAddress());
taxiHolder.dist.setText(taxi.getDist());
}
返回v;
}
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.listtaxi);
最后一个字符串[]taxiNames=getResources().getStringArray(R.array.taxi\u name\u array);
最后一个字符串[]taxiAddresses=getResources().getStringArray(R.array.taxi\u address\u array);
最后一个字符串[]taxiDist=getResources().getStringArray(R.array.taxi\u array\u dist);
ArrayList taxiList=新的ArrayList();
for(int i=0;i
}

我的地图课是: /** * */ 包com.taxime

    public class Map extends MapActivity{
LinearLayout linearLayout;
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
ItemizedOverlay itemizedOverlay;


public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapviews);

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);



        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        itemizedOverlay = new ItemizedOverlay(drawable);

        Intent intent = getIntent();
        if (intent != null) {
            if (Intent.ACTION_VIEW.equals(intent.getAction())) {
                if (intent.getData() != null) {
                    int selectedPosition = Integer.parseInt(intent.getData().getHost());
                    GeoPoint point = new GeoPoint(selectedPosition, selectedPosition);

                    OverlayItem overlayitem = new OverlayItem(point, "", "");
                    itemizedOverlay.addOverlay(overlayitem);
                    mapOverlays.add(itemizedOverlay);

                    //...
                }
            }
        }
公共类映射扩展了MapActivity{
线性布局线性布局;
地图视图;
列出地图覆盖图;
可拉伸;
ItemizedOverlay ItemizedOverlay;
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mapviews);
mapView=(mapView)findViewById(R.id.mapView);
mapView.SetBuilTinZoomControl(真);
mapOverlays=mapView.getOverlays();
drawable=this.getResources().getDrawable(R.drawable.androidmarker);
itemizedOverlay=新itemizedOverlay(可绘制);
Intent=getIntent();
if(intent!=null){
if(Intent.ACTION_VIEW.equals(Intent.getAction())){
if(intent.getData()!=null){
int selectedPosition=Integer.parseInt(intent.getData().getHost());
地质点=新的地质点(selectedPosition,selectedPosition);
OverlayItem OverlayItem=新的OverlayItem(点“,”);
itemizedOverlay.addOverlay(overlayitem);
添加(itemizedOverlay);
//...
}
    <string-array name="taxi_name_array">
    <item>Barrys Taxi</item>
    <item>Boom Taxi</item>

</string-array>

<string-array name="taxi_address_array">
<item>24 test address, Uxbridge, UB8 2JY</item>
<item>14 test 2 address, Uxbridge, UB91JD</item>
</string-array>
<string-array name = "taxi_array_dist">
<item>0.4 miles</item>
<item>0.8 miles</item>
</string-array>
<string-array name ="location">
<item>(19240000,-99120000)</item>
</string-array>
    Geocoder gc = new Geocoder(this.getApplicationContext()) ;
    List<Address> addresses = null ;

    try {
       addresses = gc.getFromLocationName("123 Main St, Peoria IL 61601", 10) ;
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }

    Address a = addresses.get(0) ;
    double lat = a.getLatitude() ;
    double lon = a.getLongitude() ;

    MapController mc = mapView.getController();

    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lon * 1E6));

    mc.animateTo(p);
    mc.setZoom(18);
    mapView.invalidate();
adb.setNeutralButton("Show Map", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("taxi:" + selectedPosition), ListTaxi.this, Map.class);
        startActivity(intent);
    }
});
Intent intent = getIntent();
if (intent != null) {
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.getData() != null) {
            int selectedPosition = Integer.parseInt(intent.getData().getHost());
            String[] taxiLocations = getResources().getStringArray(R.array.location);
            String location = taxiLocations[selectedPosition];
            //...
        }
    }
}