我在课堂上创建了一个alertdiaolog。我把一个自定义的按钮和另一个按钮拨打电话。我将这些项目设置在不同的mapActivity类中。
其实我有两个问题。一个是当我尝试用关闭按钮关闭我的alertdiaolog时没有任何事情发生第二个是当我尝试拨打电话时我得到IndexOutofBound异常错误。
这是我的代码:
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.alertmenu,
(ViewGroup) findViewById(R.id.widget0));
ImageButton alertimagebutton = (ImageButton) layout.findViewById(R.id.closebutton);
alertimagebutton.setImageResource(R.drawable.close_button);
Button alertphone = (Button) layout.findViewById(R.id.widget35);
alertphone.setText(phonevalue.get(i));
//call
alertphone.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
System.out.println(phonevalue.get(i));
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phonevalue.get(i)));
startActivity(callIntent);
} catch (Exception e) {
System.out.println("Couldn't make a call= "+e);
}
}
});
//close
alertimagebutton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
System.out.println("closed"); // logcat shows this message
MyClass.alertDialog.dismiss();
}
});
MyClass.alertDialog = builder.create();
mapOverlays.add(MyClass);
注意:我为listview activty做了同样的事情,它运行正常。当用户点击视图时,它会显示我的alertdiaolog并可以关闭并拨打电话。但是我在同一个活动中创建了我的alertdiaolog,而不是一个不同的类。
注意2:我这样做是为了当用户点击地图中的图像时我想显示有关此人的详细视图。首先我创建了气球,第二个用户单击此按钮,显示图像详细视图。
编辑:我解决了电话问题。我设置了我的phoneno后,我声明了另一个字符串变量: Button alertphone = (Button) layout.findViewById(R.id.widget35);
alertphone.setText(phonevalue.get(i));
final String phone = phonevalue.get(i);
我改变了callintent:
callIntent.setData(Uri.parse("tel:"+phone));
现在它工作正常,但我仍然无法关闭我的对话框。