Last active
January 7, 2016 21:10
-
-
Save Felipe00/bd5a6c083fe3c4ff61d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
ProductDAO dao; | |
EditText nomeProduto, descricaoProduto; | |
Button btnCadatrarProduto; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
nomeProduto = (EditText) findViewById(R.id.id_nome_produto); | |
descricaoProduto = (EditText) findViewById(R.id.id_descricao_produto); | |
btnCadastrarProduto = (Button) findViewById(R.id.id_cadastrar_produto); | |
btnCadastrarProduto.setOnClickListener(new OnClickListener() { | |
public void onClick() { | |
//Quando clicar, cadastra. | |
Produto objeto = new Produto() | |
objeto.setId(1l); | |
objeto.setName(nomeProduto.getText().toString()); | |
objeto.setDescricao(descricaoProduto.getText().toString()) | |
dao = new ProductDAO(this); //this é o contexto. | |
long deuCerto = dao.salvarProduto(objeto); | |
if (deuCerto != null) { | |
Toast.makeText(this, "Deu certo", Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(this, "Deu errado", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment