I need to create a screen that calls another one, but I want to do this using only methods, and in the code I made, it is not calling the other one.
On the first screen I have a list and a include button. When you click on the include button, you have to see another screen to enter the name, then I click on the ok button to include it and it returns to the first screen with the lists showing the new contact adds.
package com.example.pamelaelias.contatos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
ListView lista;
List lista2 = new ArrayList();
Button btnIncluir, btnOkIncluir;
EditText txtNome;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lista = (ListView) findViewById(R.id.idLista);
lista2.add("Pamela");
lista2.add("Brenda");
lista2.add("Gabriel");
final ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lista2);
lista.setAdapter(adp);
}
public void TelaInicial() {
btnIncluir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.incluir);
btnOkIncluir = (Button) findViewById(R.id.btnOkIncluir);
txtNome = (EditText) findViewById(R.id.txtNome);
Incluir();
}
});
}
public void Incluir() {
final ArrayAdapter<String> st = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, lista2);
btnOkIncluir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.activity_main);
btnIncluir = (Button) findViewById(R.id.btnIncluir);
lista = (ListView) findViewById(R.id.idLista);
lista2.add(txtNome.getText());
lista.setAdapter(st);
TelaInicial();
}
});
}
}