关闭意图对话

时间:2015-07-31 22:53:24

标签: android android-intent dialog

我有一个带有RelativeLayout的对话框,用于发送用户更改一些参数,当用户回来时再次打开对话框以显示参数已更改,这样当用户回归时我有两个对话框相互打开,怎么能我关闭了意图的对话框?

这里创建了对话框:

    public void showFitnessDialog(){    
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater     = LayoutInflater.from(getActivity());
    final View view2            = inflater.inflate(R.layout.fitness_dialog, null); 

    Cursor data = databaseHelper.selectEverything("fitness_settings");
    Cursor dat = databaseHelper.selectEverything("activity_alarm");

     String dailyGoalFromDB = "";
     String startAlarmData = "";
     String endAlarmData = "";
     String intervalAlarmData = "";
     try{
         data.moveToFirst();
         dat.moveToFirst();
         dailyGoalFromDB = data.getString(data.getColumnIndex("goal"));
         startAlarmData = dat.getString(dat.getColumnIndex("start_time"));      
         endAlarmData = dat.getString(dat.getColumnIndex("end_time"));      
         intervalAlarmData = dat.getString(dat.getColumnIndex("interval"));     

     }
     finally{
         data.close();
         dat.close();
         databaseHelper.database.close();
     }

    if(isDailyGoalset){
        RelativeLayout goal_set = (RelativeLayout) view2.findViewById(R.id.goal_set);
        goal_set.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                Intent myIntent = new Intent(getActivity(), FitnessSettings.class); 
                startActivityForResult(myIntent, GOAL_SET);     
            }
         });
        ImageView goalIndicator = (ImageView) view2.findViewById(R.id.goal_indicator);
        TextView activate = (TextView) view2.findViewById(R.id.activate);
        activate.setText("YOUR DAILY GOAL IS " + dailyGoalFromDB + " STEPS");
        goalIndicator.setImageResource(R.drawable.checked);
    }
    else {
        RelativeLayout goal_set = (RelativeLayout) view2.findViewById(R.id.goal_set);
        goal_set.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                Intent myIntent = new Intent(v.getContext(), FitnessSettings.class);
                startActivityForResult(myIntent, 1);
            }
         });
        TextView option_1 = (TextView) view2.findViewById(R.id.option_1);
        option_1.setText("Goal Unset");
        TextView activate = (TextView) view2.findViewById(R.id.activate);
        activate.setText("DEFINE YOUR DAILY GOAL");
    }

    builder.setTitle(Html.fromHtml("<font color='#55BFE7'>Fitness</font>"));
    builder.setPositiveButton("Done",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
                int which) {}
    });                 
    builder.setView(view2);
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button okButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            okButton.setOnClickListener(new View.OnClickListener() {                    
                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();                                                                                  
                }
            });             
        }
    });
    alertDialog.show();         
}
@Override
public void onResume() {
    super.onResume();
    if(Globals.isGoalUpdated){
        showFitnessDialog();
        Toast.makeText(getActivity().getBaseContext(), "True", Toast.LENGTH_LONG).show();           
    }

我想在这里关闭对话框:

  

public void onClick(View v) { Intent myIntent = new Intent(getActivity(), FitnessSettings.class); startActivityForResult(myIntent, GOAL_SET);
}

抱歉我的英文不好

1 个答案:

答案 0 :(得分:0)

make final&#34; AlertDialog alertDialog&#34;全局和他们你需要关闭呼叫alertDialog.dismiss();