0

The up link is different to my problem

i have this structure: Main -> MenuItem -> AlertDialog class -> Click Button -> (Reload) Main

I want click button reload activity main. How i can make it?

Thanks

*CLASE MAIN *

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public boolean onPrepareOptionsMenu(Menu menu) {

    MenuItem item = menu.findItem(R.id.MenuOpcColores);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.MenuOpcColores:
            CambiarColores colores = new CambiarColores(this, 
                    R.layout.cambiar_colores, 
                    R.string.cambiarColores, 
                    R.color.estandar, 
                    R.id.botonAplicarColor,
                    R.id.botonCancelarColor); 
            colores.show();  
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

}

CLASE DIALOG

public class CambiarColores extends Dialog implements          android.view.View.OnClickListener{  

Context context;


public CambiarColores(Context context, int vista, int titulo, int color, int id1, int id2) {  

    super(context);  
    this.context = context;
    this.titulo = titulo;
    this.vista = vista;
    this.color = color;
    this.id1 = id1;
    this.id2 = id2;
}  

protected void onCreate(Bundle savedInstanceState) {  

    super.onCreate(savedInstanceState);

    setContentView(vista);  
}  

@Override  
public void onClick(View v) {  

    // REFRESH MAIN 

} 
} 
laalto
  • 150,114
  • 66
  • 286
  • 303
user3092292
  • 49
  • 2
  • 2
  • 9

2 Answers2

4

to reload the activity, complete or finish the activity first and then call the intent.

finish();
startActivity(getIntent());

or follow this post, https://stackoverflow.com/a/6283098/6780216

Community
  • 1
  • 1
Kshitij Jhangra
  • 577
  • 7
  • 14
1

On the Button click execute following code:

Intent intent = new Intent(context,MainActivity.class);
context.startActivity(intent);
Naddy
  • 2,664
  • 6
  • 25
  • 38
  • Maybe you can post some code. According to my current understanding I have edited the answer. – Naddy Dec 18 '13 at 12:17
  • getAplicactionContext(), finish() and startActivity() are undefined... this is ok in main class but not in alert dialog class. **public class changeColors extends Dialog implements android.view.View.OnClickListener{** – user3092292 Dec 18 '13 at 12:38
  • getActivity() is undefined – user3092292 Dec 18 '13 at 12:41
  • Why don't you post your class in your question?? Instead of letting me guess what you have done. – Naddy Dec 18 '13 at 12:42
  • @user3092292 Thanks for posting your code. On your button click execute the updated code. It should work now. – Naddy Dec 18 '13 at 18:09