Android Open Source - jpdroid Endereco Activity






From Project

Back to project page jpdroid.

License

The source code is released under:

GNU General Public License

If you think the Android project jpdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package br.com.rafael.pedidojpdroid;
/*  w  w w.java 2s.c  om*/
import java.io.Serializable;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import br.com.rafael.jpdroid.core.Jpdroid;
import br.com.rafael.pedidojpdroid.entity.Endereco;

public class EnderecoActivity extends Activity {

  private Endereco endereco = null;
  private EditText etRua;
  private EditText etBairro;
  private EditText etNumero;

  private Spinner spCidade;
  private CheckBox chkPrincipal;
  private Jpdroid jpdroid;
  private int posicao = 0;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_endereco);

    jpdroid = Jpdroid.getInstance();

    etRua = (EditText) findViewById(R.id.etRua);
    etBairro = (EditText) findViewById(R.id.etBairro);
    etNumero = (EditText) findViewById(R.id.etNumero);
    spCidade = (Spinner) findViewById(R.id.spCidade);
    chkPrincipal = (CheckBox) findViewById(R.id.chkPrincipal);

    fillCidade();

    Intent it = getIntent();
    Serializable param = it.getExtras().getSerializable("endereco");
    if (param != null) {
      posicao = it.getIntExtra("posicao", 0);
      Endereco novo = (Endereco) param;
      endereco = novo;
      etRua.setText(endereco.getRua());
      etBairro.setText(endereco.getBairro());
      etNumero.setText(String.valueOf(endereco.getNumero()));
      chkPrincipal.setChecked(endereco.isPrincipal());
      SelectSpinnerItemByValue(spCidade, endereco.getId_Cidade());

    } else {
      endereco = new Endereco();
    }

  }

  private void SelectSpinnerItemByValue(Spinner spCidade2, long id_Cidade) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) spCidade2.getAdapter();
    for (int position = 0; position < adapter.getCount(); position++) {
      if (adapter.getItemId(position) == id_Cidade) {
        spCidade2.setSelection(position);
        return;
      }
    }

  }

  private void fillCidade() {
    String[] columns = new String[] { "_id", "nome", "sigla" };

    int[] to = new int[] { R.id.tvIdCidadeLista, R.id.tvNomeCidade, R.id.tvSiglaEstado };

    Cursor cursor = jpdroid.rawQuery(
        "SELECT CIDADE._ID, CIDADE.NOME, ESTADO.SIGLA FROM CIDADE INNER JOIN ESTADO ON (CIDADE.ID_ESTADO = ESTADO._ID)",
        null);

    SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this, R.layout.activity_lista_cidades, cursor, columns,
        to, 0);

    spCidade.setAdapter(dataAdapter);

  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.endereco, menu);
    return true;
  }

  public void btnSalvarEnderecoClicked(final View v) {

    endereco.setRua(etRua.getText().toString());
    endereco.setBairro(etBairro.getText().toString());
    if (etNumero.getText().toString().length() > 0) {
      endereco.setNumero(Long.parseLong(etNumero.getText().toString()));
    }
    Cursor crCidade = (Cursor) spCidade.getSelectedItem();
    endereco.setId_Cidade(crCidade.getLong(crCidade.getColumnIndex("_id")));
    endereco.setNomeCidade(crCidade.getString(crCidade.getColumnIndex("nome")));
    endereco.setPrincipal(chkPrincipal.isChecked());

    Intent it = new Intent();

    Bundle bundle = new Bundle();
    bundle.putSerializable("endereco", (Serializable) endereco);

    it.putExtras(bundle);
    it.putExtra("posicao", posicao);
    setResult(RESULT_OK, it);
    finish();
  }

}




Java Source Code List

br.com.rafael.jpdroid.annotations.Column.java
br.com.rafael.jpdroid.annotations.DefaultOrder.java
br.com.rafael.jpdroid.annotations.DtoField.java
br.com.rafael.jpdroid.annotations.Dto.java
br.com.rafael.jpdroid.annotations.Entity.java
br.com.rafael.jpdroid.annotations.ForeignKey.java
br.com.rafael.jpdroid.annotations.Ignorable.java
br.com.rafael.jpdroid.annotations.PrimaryKey.java
br.com.rafael.jpdroid.annotations.RelationClass.java
br.com.rafael.jpdroid.annotations.ViewColumn.java
br.com.rafael.jpdroid.converters.JpdroidCsvConverter.java
br.com.rafael.jpdroid.converters.JpdroidDateUtil.java
br.com.rafael.jpdroid.converters.JpdroidDtoConverter.java
br.com.rafael.jpdroid.converters.JpdroidJsonConverter.java
br.com.rafael.jpdroid.converters.JpdroidMatrixCursorConverter.java
br.com.rafael.jpdroid.converters.JpdroidXmlConverter.java
br.com.rafael.jpdroid.core.JpdroidAbout.java
br.com.rafael.jpdroid.core.JpdroidDbHelper.java
br.com.rafael.jpdroid.core.JpdroidEntityValidation.java
br.com.rafael.jpdroid.core.JpdroidObjectMap.java
br.com.rafael.jpdroid.core.JpdroidTransaction.java
br.com.rafael.jpdroid.core.JpdroidWriteFile.java
br.com.rafael.jpdroid.core.Jpdroid.java
br.com.rafael.jpdroid.enums.Order.java
br.com.rafael.jpdroid.enums.RelationType.java
br.com.rafael.jpdroid.enums.ScriptPath.java
br.com.rafael.jpdroid.exceptions.JpdroidException.java
br.com.rafael.jpdroid.interfaces.ITransaction.java
br.com.rafael.jpdroid.util.JpdroidConverter.java
br.com.rafael.jpdroid.util.JpdroidCsvFile.java
br.com.rafael.jpdroid.util.JpdroidJsonFile.java
br.com.rafael.jpdroid.util.JpdroidXmlFile.java
br.com.rafael.pedidojpdroid.ContatoActivity.java
br.com.rafael.pedidojpdroid.EnderecoActivity.java
br.com.rafael.pedidojpdroid.ExportacoesActivity.java
br.com.rafael.pedidojpdroid.ImportacoesActivity.java
br.com.rafael.pedidojpdroid.ItensPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaCidadesActivity.java
br.com.rafael.pedidojpdroid.ListaContatoActivity.java
br.com.rafael.pedidojpdroid.ListaEnderecoActivity.java
br.com.rafael.pedidojpdroid.ListaItensPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaPedidoActivity.java
br.com.rafael.pedidojpdroid.ListaPessoaActivity.java
br.com.rafael.pedidojpdroid.ListaProdutoActivity.java
br.com.rafael.pedidojpdroid.ListagemPedidoActivity.java
br.com.rafael.pedidojpdroid.ListagemPessoaActivity.java
br.com.rafael.pedidojpdroid.ListagemProdutoActivity.java
br.com.rafael.pedidojpdroid.PedidoActivity.java
br.com.rafael.pedidojpdroid.PesquisaDialogActivity.java
br.com.rafael.pedidojpdroid.PessoaActivity.java
br.com.rafael.pedidojpdroid.PrincipalActivity.java
br.com.rafael.pedidojpdroid.ProdutoActivity.java
br.com.rafael.pedidojpdroid.SobreActivity.java
br.com.rafael.pedidojpdroid.dto.ContatoDTO.java
br.com.rafael.pedidojpdroid.dto.PessoaDTO.java
br.com.rafael.pedidojpdroid.entity.Cidade.java
br.com.rafael.pedidojpdroid.entity.Contato.java
br.com.rafael.pedidojpdroid.entity.Endereco.java
br.com.rafael.pedidojpdroid.entity.Estado.java
br.com.rafael.pedidojpdroid.entity.ItensPedido.java
br.com.rafael.pedidojpdroid.entity.Pedido.java
br.com.rafael.pedidojpdroid.entity.Pessoa.java
br.com.rafael.pedidojpdroid.entity.Produto.java
com.rafael.androidcomjpdroid.ContatoActivity.java
com.rafael.androidcomjpdroid.MainActivity.java
com.rafael.androidcomjpdroid.PessoaActivity.java
com.rafael.androidcomjpdroid.entity.Contato.java
com.rafael.androidcomjpdroid.entity.Pessoa.java
com.rafael.androidcomjpdroid.entity.TipoContato.java