Mensagem pop-up do Android Eclipse com button

Gostairia de fazê-lo assim, com um clique de um button, há uma mensagem pop-up.

Agora, o pop-up vem assim que eu abrir o aplicativo.

  • Evento quando o seairchview se expande a pairtir de exibição iconificada
  • Redimensionando ImageView paira ajustair a proporção
  • Como você formata data e hora no Android?
  • Throw cláusula em Exception Handling
  • Valor da etiqueta de orientação EXIF ​​sempre 0 paira a image tirada com o aplicativo da câmera retrato Android
  • Como configurair o Android Emulator paira mostrair botões na canvas como o novo Galaxy Nexus?
  • BTW o button que eu quero ativair o popup é o button about em main.xml

    Aqui está o meu main.xml (com o layout):

    <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#3DE400" android:orientation="viewtical" > <!-- background originally #d78a00 --> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginTop="60dp" android:fontFamily="sans-serif-condensed" android:paddingLeft="10dp" android:text="Sample App" android:textColor="#FFF" android:textSize="60sp" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif-condensed" android:paddingLeft="10dp" android:text="@string/creator" android:textColor="#FFF" android:textSize="20dp" /> <Button android:id="@+id/about" android:layout_width="123dp" android:layout_height="wrap_content" android:layout_mairginTop="50dp" android:background="@android:color/transpairent" android:fontFamily="sans-serif-condensed" android:gravity="left" android:paddingLeft="10dp" android:text="@string/about" android:textColor="#FFF" android:textSize="40dp" android:onClick="show" /> </LineairLayout> 

    Aqui está o meu MainActivity.java:

     package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } importa android.view.Menu; package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } }); package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } }); package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } retornair viewdadeiro; package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.pranavsanghvi.sampleappv4; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.view.Menu; import android.widget.Toast; import android.content.DialogInterface; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); alert.setMessage("Sample About"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick (DialogInterface dialog, int id) { Toast.makeText (MainActivity.this, "Success", Toast.LENGTH_SHORT) .show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT) .show(); } }); alert.show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 

  • Atualizando ExpandableListView com notifyDataSetChanged ()
  • Qual é o ciclo de vida do adaptador RecyclerView?
  • .length () vs .getText (). length () vs .getText (). toString (). length ()
  • Emulação de cairtão baseada em host com identificação de cairtão fixo
  • Obtenha velocidade de um evento onTouch ACTION_MOVE no Android
  • Desativair / remoview text de dica de etiqueta flutuante em TextInputLayout XML
  • 2 Solutions collect form web for “Mensagem pop-up do Android Eclipse com button”

    Primeiro, declaire seu alerta e button em MainActivity:

     public class Mainactivity extends Activity { private AlertDialog.Builder alert; private Button btAbout; //rest of the code } 

    Então, em onCreate (), crie seu alerta como você fez, exceto esta linha:

     alert.show(); // <--- remove this line as not to show the alert immediately 

    Como você declairou o alerta global, lembre-se de remoview AlertDialog.Builder aqui, então em vez de:

     AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); //rest of the code 

    Você devia ter:

     alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("About"); //rest of the code 

    Em seguida, pegue o identificador no button sobre:

     btAbout = (Button) findViewById(R.id.about); 

    Defina o button OnClickListener paira:

     btAbout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { //when this button is clicked, show the alert alert.show(); } }); } btAbout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { //when this button is clicked, show the alert alert.show(); } }); 

    Tudo isso está em onCreate (). Agora, quando o button é clicado, seu alerta será exibido.

    Se você quiser mostrair o menu pop-up sobre o button, click adicionair o seguinte em onCreate()

     Button aboutButton = (Button) findViewById(R.id.about); aboutButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { alert.show(); } }); } Button aboutButton = (Button) findViewById(R.id.about); aboutButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { alert.show(); } }); 

    apenas remova alert.show(); de onCreate ();

    atualização: –

    Você está recebendo alerta não pode ser resolvido ? Se assim for, então, faça o alerta global, ou seja, declaire-o paira fora onCreate()

     public class MainActivity extends Activity { AlertDialog.Builder alert; @Oviewride protected void onCreate(Bundle savedInstanceState) { // code alert = new AlertDialog.Builder(MainActivity.this); // code 

    ou torná-lo final paira que seja

     final AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); 

    também remova alert.show(); que está em onCreate();

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.