AppCadastro.java
package br.com.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.app.*;
public class AppCadastro extends Activity {
 Registro pri,reg,ult,aux;
 EditText ednome,edprof,edidade;
int numreg,pos;
 void CarregaTelaPrincipal () {
 setContentView(R.layout.activity_app_cadastro);
 Button btcadpess = (Button)
findViewById(R.id.btcadastrarpessoas);
 Button btlistapess = (Button)
findViewById(R.id.btlistarpessoas);
 btcadpess.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 CarregaTelaCadastro();
 }});
 btlistapess.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 CarregaListaPessoas();
 }});
 }
 void CarregaTelaCadastro() {
 setContentView(R.layout.cadastro);
 Button btcadastrar = (Button)
findViewById(R.id.btcadastrar);
 Button btcancelar = (Button)
findViewById(R.id.btcancelar);
 btcadastrar.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 try {
 reg = new Registro();
 ednome = (EditText)findViewById(R.id.ednome);
 edprof = (EditText)findViewById(R.id.edprofissao);
 edidade = (EditText)findViewById(R.id.edidade);
 reg.nome = ednome.getText().toString();
 reg.profissao = edprof.getText().toString();
 reg.idade = edidade.getText().toString();
if(pri==null)
 pri=reg;
 reg.Ant = ult;
 if(ult==null)
 ult=reg;
 else {
 ult.Prox = reg;
 ult=reg;
 }
 numreg++;
 showMessage("Cadastro efetuado com sucesso", "Aviso");
 CarregaTelaPrincipal();
 }
 catch(Exception e) {
 showMessage("Erro ao cadastrar", "Erro");
 }}
 });
 btcancelar.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 CarregaTelaPrincipal();
 }
 });
 }
 void CarregaListaPessoas() {
 if(numreg==0) {
 showMessage("Nenhum registro cadastrado", "Aviso");
 CarregaTelaPrincipal();
 return;
 }
 setContentView(R.layout.listacadastrados);
 pos=1;
 aux=pri;
 TextView txtnome = (TextView)findViewById(R.id.txtnome);
 TextView txtidade = (TextView)findViewById(R.id.txtidade);
 TextView txtprofissao =
(TextView)findViewById(R.id.txtprofissao);
 Button btmenu = (Button) findViewById(R.id.btmenu);
 Button btavancar = (Button) findViewById(R.id.btavancar);
 Button btvoltar = (Button) findViewById(R.id.btvoltar);
 txtnome.setText(aux.nome);
 txtidade.setText(aux.idade);
 txtprofissao.setText(aux.profissao);
 btmenu.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0){
 CarregaTelaPrincipal();
 }
 });
 btvoltar.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 if(pos==1)
 return;
 pos--;
 aux=aux.Ant;
 TextView txtnome =
(TextView)findViewById(R.id.txtnome);
 TextView txtidade =
(TextView)findViewById(R.id.txtidade);
 TextView txtprofissao =
(TextView)findViewById(R.id.txtprofissao);
 txtnome.setText(aux.nome);
 txtidade.setText(aux.idade);
 txtprofissao.setText(aux.profissao);
 }
 });
 btavancar.setOnClickListener(new View.OnClickListener(){
 public void onClick(View arg0){
 if(pos==numreg)
 return;
 pos++;
 aux=aux.Prox;
 TextView txtnome =
(TextView)findViewById(R.id.txtnome);
 TextView txtidade =
(TextView)findViewById(R.id.txtidade);
 TextView txtprofissao =
(TextView)findViewById(R.id.txtprofissao);
 txtnome.setText(aux.nome);
 txtidade.setText(aux.idade);
 txtprofissao.setText(aux.profissao);
 }
 });
 }
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 numreg=0;
 pri=ult=null;
 CarregaTelaPrincipal();
}
public void showMessage(String Caption,String Title) {
AlertDialog.Builder dialogo = new
AlertDialog.Builder(AppCadastro.this);
 dialogo.setTitle(Title);
 dialogo.setMessage(Caption);
 dialogo.setNeutralButton("OK", null);
 dialogo.show();
 }
}
activity_app_cadastro.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="br.com.android.AppCadastro" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="289dp"
        android:layout_height="102dp"
        android:src="@drawable/icone" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Bem vindo à Aplicação de Cadastro de Pessoas. Este é um pequeno programa de demosntração de cadastro. Selecionar uma das opções abaixo: " />
    <Button
        android:id="@+id/btcadastrarpessoas"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Cadastrar Pessoas" />
    <Button
        android:id="@+id/btlistarpessoas"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Listar Pessoas Cadastradas" />
</LinearLayout>
cadastro.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="126dp"
        android:src="@drawable/icone" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Módulo sw cadastro, digite seus dados abaixo:" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nome: " />
    <EditText
        android:id="@+id/ednome"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" >
        <requestFocus />
    </EditText>
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Profissão: " />
    <EditText
        android:id="@+id/edprofissao"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />
    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Idade:" />
    <EditText
        android:id="@+id/edidade"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btcadastrar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.49"
            android:text="Cadastrar Pessoas" />
        <Button
            android:id="@+id/btcancelar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.44"
            android:text="Cancelar" />
    </LinearLayout>
</LinearLayout>
listacadastrados.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="115dp"
        android:src="@drawable/icone" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Lista de Pessoas Cadastradas"
        android:textColor="#FF0000"
        android:textSize="20sp" />
    <LinearLayout
        android:id="@+id/layoutNome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/txtnome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nome: "
            android:textColor="#FF0000"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/layoutProfissao"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/txtprofissao"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Profissão: "
            android:textColor="#FF0000"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/layoutidade"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/txtidade"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Idade: "
            android:textColor="#ff0000"
            android:textSize="20sp" />
    </LinearLayout>
        <LinearLayout
            android:id="@+id/layoutBotoes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <Button
                android:id="@+id/btvoltar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.51"
                android:text="Voltar" />
            <Button
                android:id="@+id/btavancar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.36"
                android:text="Avançar" />
        </LinearLayout>
        <Button
            android:id="@+id/btmenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Menu Principal" />
    </LinearLayout>
Registro.java
package br.com.android;
public class Registro {
 String nome;
 String profissao;
 String idade;
 Registro Prox;
 Registro Ant;
 
}
 




 
 
0 comentários:
Postar um comentário