Android Studio dialog doesn't work

Multi tool use
Multi tool use


Android Studio dialog doesn't work



I am trying to create multi question dialog. It seems that everything is working fine expect that I cannot get result of numberpicker + I have leaking window in the end



This is my code:


final Context context = this;
int currentshape, goalshape=9,qnumber=1,gender,age; // 0 = lean , 1 = fat , 2 = skinny fat || 0 = shredded , 1 = powerlifter, 2 = bodybuiler.
int height,weight;
Boolean flag=false,flag2=false,flag3=false;
int year;
Button current, goals; // buttons
public static final String PREFS_NAME = "MyApp_Settings";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question1);
current = new Button[3];
goals = new Button[3];
current[0] = (Button) findViewById(R.id.btnLean);
current[1] = (Button) findViewById(R.id.btnFat);
current[2] = (Button) findViewById(R.id.btnSkinnyFat);
for (int i = 0; i < 3; i++)
current[i].setOnClickListener(this);
}

public void questions1() {
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.question2);
if(flag2 == false)
dialog.show();
Button btn = new Button[3];
btn[0] = (Button) dialog.findViewById(R.id.btnShrededd);
btn[1] = (Button) dialog.findViewById(R.id.btnBodyBuilding);
btn[2] = (Button) dialog.findViewById(R.id.btnPowerLifting);
for (int i = 0; i < 3; i++)
btn[i].setOnClickListener(this);
if(flag2 == true) {
dialog.dismiss();
}
this.flag2=true;
}
private double parseDouble(String s){
if(s == null || s.isEmpty())
return 0.0;
else
return Double.parseDouble(s);
}
public void questions2() {
Dialog dialog2 = new Dialog(context);
dialog2.setContentView(R.layout.question3);
if(flag == false && flag3 == false) {
dialog2.show();
Button btn = new Button[3];
final NumberPicker tv = new NumberPicker[3];
tv[0] = (NumberPicker) dialog2.findViewById(R.id.weight);
tv[1] = (NumberPicker) dialog2.findViewById(R.id.height);
tv[2] = (NumberPicker) dialog2.findViewById(R.id.age);
btn[0] = (Button) dialog2.findViewById(R.id.btnmale);
btn[1] = (Button) dialog2.findViewById(R.id.btnwomen);
btn[2] = (Button) dialog2.findViewById(R.id.btnsetupfinish);
for (int i = 0; i < 3; i++) {
btn[i].setOnClickListener(this);
tv[i].setMinValue(1);
tv[i].setMaxValue(150);
}
if (flag == true && flag3 == false) {
this.weight = tv[0].getValue();
this.height = tv[1].getValue();
this.age = tv[2].getValue();
this.flag3 = true;
}
}
if (flag3){
dialog2.dismiss();
}
flag = true;
}

@Override
protected void onPause() {
super.onPause();
questions2();
Log.d("crash",this.weight + " " + this.height);
}

public void updatesharepref(){
SharedPreferences sharedPref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnLean:
this.currentshape = 0;
questions1();
break;
case R.id.btnFat:
this.currentshape = 1;
questions1();
break;
case R.id.btnSkinnyFat:
this.currentshape = 2;
questions1();
break;
case R.id.btnShrededd:
this.goalshape=0;
questions2();
break;
case R.id.btnPowerLifting:
this.goalshape=1;
questions2();
break;
case R.id.btnBodyBuilding:
this.goalshape=2;
questions2();
break;
case R.id.btnmale:
this.gender=1;
break;
case R.id.btnwomen:
this.gender=2;
break;
case R.id.btnsetupfinish:
flag=true;
questions2();
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
finish();
break;
}



I know the code isnt the prettiest but I am beginner. I tried to make multi dialog questions so I could get info about user. After finishing the dialogs I cannot receive the number in the NumberPicker widget as it always returns 0. Plus questions2 dialog leaks all the time.



Error log:


E/WindowManager: android.view.WindowLeaked: Activity com.example.gold.mnfitness.First_login has leaked window DecorView@5ed0dc1 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:485)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
at android.app.Dialog.show(Dialog.java:330)
at com.example.gold.mnfitness.First_login.questions2(First_login.java:82)
at com.example.gold.mnfitness.First_login.onClick(First_login.java:144)





tried this stackoverflow.com/a/2850597/886148 ?
– wick.ed
Jun 30 at 23:37





i had tried but it dosent seems to work the problem with saving the numberpicker is the thing thats annoying me.
– Matan Nahamani
Jul 1 at 7:43





solved finally found a fix to the problem.
– Matan Nahamani
Jul 1 at 8:40





you should post the solution as an answer for others who end up here. :)
– wick.ed
2 days ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

K dlVyu7ZDUc,HjduJ1VV
rYu9YN,1BNuP07 8U7MnZqLXAOg2V3aj ujs

Popular posts from this blog

Rothschild family

Cinema of Italy