[Solved] AlertDialog, kill activity onClick “NO” [duplicate]

You need to provide an OnClickListener where you can call finish() for your activity. .setNegativeButton(android.R.string.no, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //replace MainActivity with your activity’s name MainActivity.this.finish(); } }) solved AlertDialog, kill activity onClick “NO” [duplicate]

[Solved] how can i make spinner inside alert dialog box in android?

Replace your code with this: public class SubMenu extends AppCompatActivity { JSONObject jsonobject; JSONArray jsonarray; ListView listview; ListViewAdapter adapter; ProgressDialog mProgressDialog; ArrayList<HashMap<String, String>> arraylist; static String RANK = “id”; static String COUNTRY = “name”; static String FLAG = “image”; Integer i = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub_menu); Toolbar toolbar = (Toolbar) … Read more

[Solved] get the selected value position

Try this way,hope this will help you to solve you problem. main.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” android:gravity=”center”> <Button android:id=”@+id/btnSelectGender” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Select Gender”/> </LinearLayout> MyActivity.java public class MyActivity extends Activity { private Button btnSelectGender; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnSelectGender = (Button) findViewById(R.id.btnSelectGender); btnSelectGender.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) … Read more

[Solved] AlertDialog OnBackPressed() Not Working Properly

Use this code for exit or closing app programically @Override public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(“Exit Application?”); alertDialogBuilder .setMessage(“Click yes to exit!”) .setCancelable(false) .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { moveTaskToBack(true); android.os.Process.killProcess(android.os.Process.myPid()); System.exit(1); } }) .setNegativeButton(“No”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); … Read more