+ Post New Thread
Results 1 to 8 of 8
Coding Thread, Any would be Android developers out there? in Coding and Web Development; I'm currently developing a tiny app that loads an AlertDialog. At the moment I have an activity and this loads ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241

    Any would be Android developers out there?

    I'm currently developing a tiny app that loads an AlertDialog. At the moment I have an activity and this loads the AlertDialog straight away. This method has two problems:

    1) The main view loads behind the AlertDialog. I want the AlertDialog to display over the top of the home screen instead.
    2) The AlertDialog is the only part of the app. When the user presses the back button it currently closes the AlertDialog and sits at the main view until the user presses back again. What I want is so this AlertView is the activity if that makes sense, so when the user presses back once it goes back to the home screen.

    What's the best way to achieve this?

  2. #2

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,812
    Thank Post
    1,476
    Thanked 592 Times in 444 Posts
    Rep Power
    168
    COuld you acheive 2 by calling finish() type method which would close the app

    Activity | Android Developers

    And maybe what you need to do is make your app a widget to acheive 1?

    regards

    Simon

  3. #3

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    I've achieved 1 by simply using a translucent theme, as well as a hidden title bar. How do I go about testing for the alertdialog to close and then closing the app when it does.

    when (alertdialog is not open)
    {
    close activity
    }

  4. #4

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,812
    Thank Post
    1,476
    Thanked 592 Times in 444 Posts
    Rep Power
    168
    I'll have to have a closer look at the code for my app tonight to see if/how to do it

    Simon

  5. #5

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,812
    Thank Post
    1,476
    Thanked 592 Times in 444 Posts
    Rep Power
    168
    Code:
        public boolean onOptionsItemSelected(MenuItem item) {
    //        Button clickBtn;
            // make an alert dialog box for the autoChangeTime when over speed limit
           AlertDialog.Builder alert = new AlertDialog.Builder(this);
    
            alert.setTitle("Auto Change");
            alert.setMessage("Enter new value (in secs) for automatic speed limit change when in red zone");
    
            // Set an EditText view to get user input 
            final EditText input = new EditText(this);
            alert.setView(input);
    
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              Editable value = input.getText();
              autoChangeTime =  Integer.parseInt(value.toString());
              finish();
    
              }
            });
    
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
              }
            });
    
    
            debug("onOptionsItemSelected: " + item.getItemId() + " save: " + R.id.menuSaveKml);
            switch (item.getItemId()) {
            case R.id.menuAutoChangeTime:
                    alert.show();
            
            break;
    I just added the finish() inside my OK listener and it seems to do the trick.

    regards

    Simon

  6. #6

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,812
    Thank Post
    1,476
    Thanked 592 Times in 444 Posts
    Rep Power
    168
    I just re-read the OP and realised you want it on the back button but hopefully sticking the finish in the cancel method will do the same trick

    Simon

  7. #7

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by SimpleSi View Post
    I just re-read the OP and realised you want it on the back button but hopefully sticking the finish in the cancel method will do the same trick

    Simon
    by cancel method I assume you mean setNegativeButton? If so, this didn't work.

  8. #8

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,812
    Thank Post
    1,476
    Thanked 592 Times in 444 Posts
    Rep Power
    168
    Code:
    	    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    	      public void onClick(DialogInterface dialog, int whichButton) {
    	        // Canceled.
    	    	  finish();
    	      }
    	    });
    
    	    alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
    			public void onCancel(DialogInterface arg0) {
    				// TODO Auto-generated method stub
    		    	  finish();
    			}
    		});
    Ok - i added the finish() to the setNegativeButton listener and added a new listener for the general cancel event (which seems to be invoked when I press the back button)
    Seems to do the job for me

    regards

    Simon

SHARE:
+ Post New Thread

Similar Threads

  1. Android App Developers
    By SimpleSi in forum Netbooks, PDA and Phones
    Replies: 2
    Last Post: 11th June 2010, 09:57 AM
  2. Request for c# developers
    By monkeyx in forum Coding
    Replies: 5
    Last Post: 8th June 2009, 01:03 PM
  3. .net developers
    By SpecialAgent in forum Educational IT Jobs
    Replies: 0
    Last Post: 15th November 2007, 01:51 PM
  4. EduGeek 2.0 Developers Wanted
    By Irazmus in forum General EduGeek News/Announcements
    Replies: 20
    Last Post: 19th July 2007, 04:48 PM
  5. Developers Wanted
    By russdev in forum Group Project
    Replies: 13
    Last Post: 28th February 2007, 12:13 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •