Loop and AlertDialog

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Loop and AlertDialog

Postby orcking » Fri Oct 31, 2008 7:10 pm

I have a main view where I want to loop and display an AlertDialog for user input and continue the loop only after the user enters OK or Cancel (I need to show the dialog blocking)

the problem is the .show() of the alert dialog is not blocking..

anyone can tell me how to do this???
orcking
Freshman
Freshman
 
Posts: 7
Joined: Thu Oct 30, 2008 10:19 pm

Top

AlertDialog.Builer

Postby Xeno » Fri Oct 31, 2008 9:25 pm

Create a layout for your input.
Create an AlertDialog.Builder

here is an example:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. LayoutInflater inflater = LayoutInflater.from(this);
  3.  
  4. View input = inflater.inflate(R.layout.your_input_layout, null);
  5.  
  6.                
  7.  
  8. new AlertDialog.Builder(this)
  9.  
  10.     .setView(input)
  11.  
  12.     .setNeutralButton("OK", new DialogInterface.OnClickListener() {
  13.  
  14.         @Override
  15.  
  16.         public void onClick(DialogInterface dialog, int which) {
  17.  
  18.             // do work here
  19.  
  20.         }
  21.  
  22.     .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
  23.  
  24.         @Override
  25.  
  26.         public void onClick(DialogInterface dialog, int which) {
  27.  
  28.             dialog.dismiss();
  29.  
  30.         }
  31.  
  32.     }).show();
  33.  
  34.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


That will show an alert dialog with whatever you set as your view untill you hit cancel or ok. You can then return any input information to the main view.

Hopefully this will help you.
I think, therefore I am.
I think, therefore I think I am.
Xeno
Freshman
Freshman
 
Posts: 6
Joined: Fri Oct 31, 2008 5:02 pm

Postby matinba » Fri Nov 28, 2008 10:56 pm

I have problems using your code. Maybe you can give me some advice. The dialog is never shown or rather the programm just goes on.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         setContentView(R.layout.update);
  2.  
  3.                         LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  4.  
  5. //LayoutInflater inflater = LayoutInflater.from(this);
  6.  
  7.                         View input = inflater.inflate(R.layout.update, null, true);
  8.  
  9.  
  10.  
  11.                         AlertDialog.Builder UpdateVorhandenDialog1=new AlertDialog.Builder(Session.this)
  12.  
  13.                         .setView(input)
  14.  
  15.                         .setMessage(sUpdateVorhandenMessage)
  16.  
  17.                         .setNeutralButton("Ja", new DialogInterface.OnClickListener() {
  18.  
  19.                                 public void onClick(DialogInterface dialog, int which) {
  20.  
  21.                                         // startupdate();
  22.  
  23.                                         log("start update");
  24.  
  25.                                 }}).setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
  26.  
  27.  
  28.  
  29.                                         public void onClick(DialogInterface dialog, int which) {
  30.  
  31.                                                 log("update ignorieren");
  32.  
  33.                                                 dialog.dismiss();
  34.  
  35.                                         }
  36.  
  37.                                 });
  38.  
  39.  
  40.  
  41.                         UpdateVorhandenDialog1.show();
  42.  
  43.                                      //Continue here after Cancel was clicked
  44.  
  45.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


MyView update.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <RelativeLayout
  4.  
  5.         xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.         android:orientation="vertical" android:layout_width="fill_parent"
  8.  
  9.         android:layout_height="fill_parent">
  10.  
  11.  
  12.  
  13. </RelativeLayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I guess I have something wrong with my view? Any advice?
matinba
Freshman
Freshman
 
Posts: 5
Joined: Thu Oct 16, 2008 3:50 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests