Atualmente estou usando uma EditText e um botão para inserir meus dados no SQLite, dessa forma:
[code]btadicionar = (Button) findViewById(R.id.btadicionar);
btadicionar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
datasource.open();
Empresas c = datasource.createEmpresas(edtNome.getText().toString());
datasource.close();[/code]
Porém quando faço isso no AlertDialog dá erro. Segue abaixo meu AlertDialog:
[code]//ALERT DIALOG CADASTRO
@SuppressWarnings("deprecation")
public void CadastrarEmpresa(View button) {
// Creates the dialog if necessary, then shows it.
// Will show the same dialog if called multiple times.
showDialog(DLG_EXAMPLE1);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DLG_EXAMPLE1:
return createExampleDialog();
default:
return null;
}
}
/**
* If a dialog has already been created,
* this is called to reset the dialog
* before showing it a 2nd time. Optional.
*/
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DLG_EXAMPLE1:
// Clear the input box.
EditText text = (EditText) dialog.findViewById(edtNome);
text.setText("");
break;
}
}
/**
* Create and return an example alert dialog with an edit text box.
*/
private Dialog createExampleDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Cadastrar Empresa");
builder.setMessage("Nome da empresa:");
// Use an EditText view to get user input.
final EditText input = new EditText(this);
input.setId(edtNome);
builder.setView(input);
//AO APERTAR BOTÃO POSITIVO
builder.setPositiveButton("Cadastrar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg) {
datasource.open();
Empresas c = datasource.createEmpresas(edtNome.getText().toString()); //DÁ ERRO NO "edtNome.getText()"
datasource.close();
}
private void cadastro() {
// TODO Auto-generated method stub
}
});
//AO APERTAR BOTÃO NEGATIVO
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
return builder.create();
}[/code]