AlertDialog on 1.5

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

AlertDialog on 1.5

Postby waideman » Tue Apr 28, 2009 7:00 pm

Hello All!

I need update my code from showAlert(1.1) to AlertDialog (1.5) but an error occurs
"The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined"



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.appcadastro;
  2.  
  3.  
  4.  
  5.  
  6.  
  7. import android.app.Activity;
  8.  
  9. import android.app.AlertDialog;
  10.  
  11. import android.app.Dialog;
  12.  
  13. import android.os.Bundle;
  14.  
  15. import android.widget.*;
  16.  
  17. import android.view.*;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. public class AppCadastro extends Activity {
  24.  
  25.     /** Called when the activity is first created. */
  26.  
  27.     Registro pri,reg,ult,aux;
  28.  
  29.    
  30.  
  31.     EditText ednome,edprof,edidade;
  32.  
  33.    
  34.  
  35.    
  36.  
  37.     int numreg,pos;
  38.  
  39.    
  40.  
  41.    
  42.  
  43.     void CarregaTelaCadastro() {
  44.  
  45.         setContentView(R.layout.cadastro);
  46.  
  47.        
  48.  
  49.        
  50.  
  51.         Button btcadastrar = (Button) findViewById(R.cadastro.btcadastro);
  52.  
  53.         Button btvoltar = (Button) findViewById(R.cadastro.btvoltar);
  54.  
  55.          
  56.  
  57.            btcadastrar.setOnClickListener(new View.OnClickListener(){
  58.  
  59.         public void onClick(View arg0){
  60.  
  61.            
  62.  
  63.                 try {
  64.  
  65.        
  66.  
  67.             reg = new Registro();
  68.  
  69.            
  70.  
  71.             ednome = (EditText)findViewById(R.campo.nome);
  72.  
  73.             edprof = (EditText)findViewById(R.campo.profissao);
  74.  
  75.             edidade = (EditText)findViewById(R.campo.idade);
  76.  
  77.            
  78.  
  79.            
  80.  
  81.             reg.nome = ednome.getText().toString();
  82.  
  83.             reg.profissao = edprof.getText().toString();
  84.  
  85.             reg.idade = edidade.getText().toString();
  86.  
  87.            
  88.  
  89.             if(pri==null)
  90.  
  91.                 pri=reg;
  92.  
  93.            
  94.  
  95.             reg.Ant = ult;
  96.  
  97.             if(ult==null)
  98.  
  99.                 ult=reg;
  100.  
  101.             else {
  102.  
  103.                 ult.Prox = reg;
  104.  
  105.                 ult=reg;
  106.  
  107.             }
  108.  
  109.            
  110.  
  111.             numreg++;
  112.  
  113.              
  114.  
  115.             AlertDialog dialog = new AlertDialog.Builder(this).create();
  116.  
  117.             dialog.setTitle("OK");
  118.  
  119.             dialog.setMessage("Cadastro efetuado com sucesso");
  120.  
  121.             dialog.show();
  122.  
  123.            
  124.  
  125.         }
  126.  
  127.         catch(Exception e) {
  128.  
  129.                 AlertDialog dialog1 = new AlertDialog.Builder(this).create();
  130.  
  131.             dialog1.setTitle("Erro!");
  132.  
  133.             dialog1.setMessage("Erro no cadastro");
  134.  
  135.             dialog1.show();
  136.  
  137.            
  138.  
  139.         }}
  140.  
  141.     });
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


somebody knows how to solve it?
tks!
waideman
Freshman
Freshman
 
Posts: 5
Joined: Thu Apr 09, 2009 1:13 pm

Top

Postby nmc » Tue Apr 28, 2009 7:18 pm

Replacing 'new AlertDialog.Builder(this)' with 'new AlertDialog.Builder(arg0.getContext())' should do the trick.
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby padde » Tue Apr 28, 2009 7:18 pm

padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby kutch » Tue Apr 28, 2009 7:19 pm

Doesn't using "AppCadastro.this" instead of just "this" work as well?
kutch
Freshman
Freshman
 
Posts: 5
Joined: Tue Apr 28, 2009 7:12 pm

Postby waideman » Tue Apr 28, 2009 7:25 pm

kutch wrote:Doesn't using "AppCadastro.this" instead of just "this" work as well?


It worked well! Thanks kutch!
waideman
Freshman
Freshman
 
Posts: 5
Joined: Thu Apr 09, 2009 1:13 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests