Can we call showAlert() on Clickevent of button???

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

Can we call showAlert() on Clickevent of button???

Postby goelsvaibhav » Mon Oct 20, 2008 12:11 pm

Hi friends,

I am new to Android development......
I wanna to display an alert whenever a user presses a button.
As i wrote showAlert() in

public void onClick(View v)

{
showAlert(" title", "Trial!", "Hello!", false));
}

an error is displayed "this method is undefined for type new View.onClickListener(){}"


Please help me out.....

Thanks in advance
Vaibhav Goel
goelsvaibhav
Junior Developer
Junior Developer
 
Posts: 19
Joined: Fri Oct 17, 2008 7:07 am
Location: Gurgaon, India

Top

Postby MrSnowflake » Mon Oct 20, 2008 12:13 pm

Try calling Allert from the Ativity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. MyActivity.this.showAlert(" title", "Trial!", "Hello!", false));
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

You are actually in an other class when you are in OnClickListener. So calling MyActivity.this will call the function from the current instance of MyAcitivty.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby goelsvaibhav » Mon Oct 20, 2008 12:24 pm

MrSnowflake wrote:Try calling Allert from the Ativity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MyActivity.this.showAlert(" title", "Trial!", "Hello!", false));
  2.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

You are actually in an other class when you are in OnClickListener. So calling MyActivity.this will call the function from the current instance of MyAcitivty.


Thanks for quick reply..
but same error is coming when i replaced showAlert with the above text......
goelsvaibhav
Junior Developer
Junior Developer
 
Posts: 19
Joined: Fri Oct 17, 2008 7:07 am
Location: Gurgaon, India

Postby MrSnowflake » Mon Oct 20, 2008 12:27 pm

I'm gonna try it myself now!

[edit]There is no such thing as showError(). Not in Activity, not in Context.
Oh, I get it, you found it in the Mini-tut?
You should use the AlertDialog.Builder now.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 new AlertDialog.Builder(this).setTitle("Error")
  3.  
  4.                 .setMessage("Could not connect.")
  5.  
  6.                 .setNeutralButton("Close", new android.content.DialogInterface.OnClickListener() {
  7.  
  8.                         @Override
  9.  
  10.                         public void onClick(DialogInterface dialog, int which) {
  11.  
  12.                                 MyActivity.this.finish();
  13.  
  14.                         }
  15.  
  16.                 }).show();
  17.  
  18.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby goelsvaibhav » Mon Oct 20, 2008 12:38 pm

MrSnowflake wrote:I'm gonna try it myself now!

[edit]There is no such thing as showError(). Not in Activity, not in Context.
Oh, I get it, you found it in the Mini-tut?
You should use the AlertDialog.Builder now.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 new AlertDialog.Builder(this).setTitle("Error")
  2.                 .setMessage("Could not connect.")
  3.                 .setNeutralButton("Close", new android.content.DialogInterface.OnClickListener() {
  4.                         @Override
  5.                         public void onClick(DialogInterface dialog, int which) {
  6.                                 MyActivity.this.finish();
  7.                         }
  8.                 }).show();
  9.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4



thanks......even i wasn't able to find showALert method..........person might have defined a separate method in which alertDialog might have been used....
goelsvaibhav
Junior Developer
Junior Developer
 
Posts: 19
Joined: Fri Oct 17, 2008 7:07 am
Location: Gurgaon, India

Postby MrSnowflake » Mon Oct 20, 2008 12:39 pm

goelsvaibhav wrote:thanks......even i wasn't able to find showALert method..........person might have defined a separate method in which alertDialog might have been used....
No, it was in a previous version of the SDK.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby today913 » Sun May 31, 2009 7:00 am

showAlert() function has been removed from the version 0.9r1 of Android SDK
today913
Freshman
Freshman
 
Posts: 5
Joined: Sun May 31, 2009 4:25 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests