我在关闭自定义的警报对话框时遇到问题。那就是它有一个包含两个按钮的自定义视图,一个用于数据库操作,另一个用于加载另一个活动。我想在执行数据库操作后关闭对话框。但是现在我不能声明任何命令,或者dialog.dismiss()
请有人帮我解决这个问题。cancel()
finish()
我的课
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
final String title= item.getTitle();
final String snippet= item.getSnippet();
AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
if(title.equalsIgnoreCase("Your Location")){
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
}
else if(title.equalsIgnoreCase("")){
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
final Button park_button = new Button(context);
park_button.setHint("Park here");
// park_button.setBackgroundResource();
layout.addView(park_button);
park_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("parkbutton:Clicked");
// Delete DB Values
int count = db.getDatasCount();
for(int i = 0;i<count;i++){
db.deleteValues(i);
}
//latitude & longtitude (string)
String latitude = String.valueOf(lat);
String longtitude = String.valueOf(lon);
Log.d("Insert: ", "Inserting ..");
db.addData(new Datas(latitude, longtitude));
// Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show();
// Reading DB Data
Log.d("Reading: ", "Reading all Values...");
List<Datas> datas = db.getAllDatas();
for (Datas dat : datas) {
String log = "Id: "+dat.getID()+" ,Latitude: " + dat.getlat() + " ,Longtitude: " + dat.getlon();
// Writing DB data to log
Log.d("DB Data: ", log);
}
Intent f = new Intent(context,MainTabActivity.class);
context.startActivity(f);
}
});
final Button know_more_button = new Button(context);
know_more_button.setHint("Know more");
// park_button.setBackgroundResource();
layout.addView(know_more_button);
know_more_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences prefs = context.getSharedPreferences("myprefs", 0);
SharedPreferences.Editor editor =prefs.edit();
editor.putString("KEY_REFERENCE", snippet);
editor.commit();
Intent intent = new Intent(context, SinglePlaceActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
dialog.setView(layout);
dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
}
public void populateNow(){
this.populate();
}
}