0

I have numerous GeoPoints and when any GeoPoint is selected a layout is inflated above the GeoPoint giving the user details on that that location. 在 infalted 布局中有一个 imageButton 但我似乎无法点击它,我不知道为什么!下面显示了我创建的代码,该代码将兴趣点添加到地图中,并使用信息填充膨胀的布局。

//show the place markers on map.
    for (int i = 0; i<mListPlaceData.size(); i++){
        PlaceData data = mListPlaceData.get(i);
        data.marker = mMap.addMarker(new MarkerOptions().position(new LatLng(data.lat, data.lon)).
                icon(BitmapDescriptorFactory.fromResource(R.drawable.place_mark))); //show place mark on map
        data.marker.setSnippet(String.valueOf(i));//set index of the data
        mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker arg0) {

                return null;
            }

            @Override
            public View getInfoContents(Marker arg0) {
                View v = getLayoutInflater().inflate(R.layout.place_detail, null);
                String pos = arg0.getSnippet(); //get index of the marker data
                try{
                    int ipos = Integer.parseInt(pos);
                    PlaceData data = mListPlaceData.get(ipos); //get the data by index
                    ((TextView)v.findViewById(R.id.txtName)).setText(data.name); //show name of the place
                    ((TextView)v.findViewById(R.id.txtHours)).setText("Hours: "+data.hours); //show hours of the place
                    ((TextView)v.findViewById(R.id.txtCountry)).setText("Country: "+data.country); //show country of the place
                    ((TextView)v.findViewById(R.id.txtAddress)).setText("Address: "+data.address); //show address of the place
                    ((TextView)v.findViewById(R.id.txtPostCode)).setText("Postcode: "+ data.postcode); //show postcode of the place

                    View.OnClickListener imageDirections = new View.OnClickListener() {
                        public void onClick(View v) {
                            Toast.makeText(TrackingServiceActivity.this,
                                    "ImageButton is clicked!", Toast.LENGTH_SHORT).show();
                        }
                      };


                      imageButton = (ImageButton) v.findViewById(R.id.imageButton1);
                      imageButton.setOnClickListener(imageDirections);

                }catch(Exception e){

                }
                return v;
            }
        });

    }
4

1 回答 1

1

ImageButton的声明是错误的。改变

imageButton = (ImageButton) findViewById(R.id.imageButton1);

imageButton = (ImageButton) v.findViewById(R.id.imageButton1);
于 2014-04-17T14:14:49.937 回答