Java can';t在膨胀视图内按下图像按钮
我有许多地质点,当选择任何地质点时,会在该地质点上方展开布局,向用户提供该位置的详细信息。在infalted布局中有一个imageButton,但我似乎无法单击它,我不知道为什么!下面显示了我创建的代码,该代码将兴趣点添加到地图中,并用信息填充膨胀的布局Java can';t在膨胀视图内按下图像按钮,java,android,android-imagebutton,Java,Android,Android Imagebutton,我有许多地质点,当选择任何地质点时,会在该地质点上方展开布局,向用户提供该位置的详细信息。在infalted布局中有一个imageButton,但我似乎无法单击它,我不知道为什么!下面显示了我创建的代码,该代码将兴趣点添加到地图中,并用信息填充膨胀的布局 //show the place markers on map. for (int i = 0; i<mListPlaceData.size(); i++){ PlaceData data = mListPlace
//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;
}
});
}
//在地图上显示位置标记。
对于(int i=0;i您的ImageButton
的声明是错误的。更改
imageButton = (ImageButton) findViewById(R.id.imageButton1);
与
因此,删除try-catch以查看是否引发了任何其他异常,或者只添加e.printStackTrace()
我删除了try/catch,它没有产生任何影响,也没有抛出任何错误,似乎当我试图按下imageButton时,整个膨胀视图高亮显示,按下按钮没有被注册,因此我想你应该向我们提供更多的代码和信息。你到底在做什么。
imageButton = (ImageButton) v.findViewById(R.id.imageButton1);