Olá, estou tendo um problema no envio das informações, que sai de da Activity 1, passa pela Activity 2 e é editado/cadastrado na Activity 3 e na configuração do delete através do menu, explico:
Activity 1: Possui uma lista com cartão de credito já cadastrado e um botão para adicionar um novo cartão.
Activity 2: Possui os campos de TextView de Numero do cartão e data de vencimento. E um menu na barra superior com a opção de Editar ou Deletar.
Activity 3:Possui os campos para o cadastro e edição do cartão de credito (Numero do cartão, data de vencimento e cvv) e um botão de salvar.
Obs: Estou me baseando nas aula 5 do modulo I e me inspirando no app do Uber na parte de Pagamentos que possui essas telas.
Segue o código das activitys atualmente;
Activity 1
public class UserPaymentsActivity extends AppCompatActivity {
private ListView listCreditCards;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_payments);
listCreditCards = (ListView) findViewById(R.id.ListViewCreditCard);
listCreditCards.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Credit_Card credit_Card = (Credit_Card) listCreditCards.getItemAtPosition(position);
Intent intentGoEditDeleteCreditCard = new Intent(UserPaymentsActivity.this, EditDeleteCreditCardActivity.class);
intentGoEditDeleteCreditCard.putExtra("credit_card", credit_Card);
startActivity(intentGoEditDeleteCreditCard);
}
});
ImageButton buttonImgBack = (ImageButton) findViewById(R.id.imageButtonBack);
buttonImgBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentBack = new Intent(UserPaymentsActivity.this, MainActivity.class);
startActivity(intentBack);
}
});
Button buttonAddCard = (Button) findViewById(R.id.buttonAddCard);
buttonAddCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentAddCard = new Intent(UserPaymentsActivity.this, AddCreditCardActivity.class);
startActivity(intentAddCard);
}
});
Button buttonOrders = (Button) findViewById(R.id.buttonOrders);
buttonOrders.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentOrders = new Intent(UserPaymentsActivity.this, OrdersActivity.class);
startActivity(intentOrders);
}
});
}
private void chargeList() {
Credit_CardDAO dao = new Credit_CardDAO(this);
List<Credit_Card> credit_Cards = dao.searchCreditCards();
dao.close();
ArrayAdapter<Credit_Card> adapter = new ArrayAdapter<Credit_Card>(this, android.R.layout.simple_list_item_1, credit_Cards);
listCreditCards.setAdapter(adapter);
}
@Override
protected void onResume() {
super.onResume();
chargeList();
}
}
Activity 2
public class EditDeleteCreditCardActivity extends AppCompatActivity {
private Credit_CardHelper helper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_delete_credit_card);
helper = new Credit_CardHelper();
ImageButton buttonImgBack = (ImageButton) findViewById(R.id.imageButtonBack);
buttonImgBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentBack = new Intent(EditDeleteCreditCardActivity.this, UserPaymentsActivity.class);
startActivity(intentBack);
}
});
Intent intent = getIntent();
Credit_Card credit_Card = (Credit_Card) intent.getSerializableExtra("credit_card");
if (credit_Card != null){
helper.fillCreditCard(credit_Card);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_crud, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
helper = new Credit_CardHelper(this);
switch (item.getItemId()){
case R.id.crud_edit:
Intent intentEdit = new Intent(EditDeleteCreditCardActivity.this, AddCreditCardActivity.class);
startActivity(intentEdit);
finish();
break;
case R.id.crud_delete:
Credit_Card credit_card = helper.takeCreditCard();
// Credit_CardDAO dao = new Credit_CardDAO(this);
// dao.delete(credit_card);
// dao.close();
//
Intent intentDelete = new Intent(EditDeleteCreditCardActivity.this, UserPaymentsActivity.class);
startActivity(intentDelete);
Toast.makeText(EditDeleteCreditCardActivity.this, "Cartão de credito" + credit_card.getId_Credit_Card() + "deletado", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
Activity 3
public class AddCreditCardActivity extends AppCompatActivity {
private Credit_CardHelper helper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_credit_card);
helper = new Credit_CardHelper(this);
ImageButton buttonImgBack = (ImageButton) findViewById(R.id.imageButtonBack);
buttonImgBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentBack = new Intent(AddCreditCardActivity.this, EditDeleteCreditCardActivity.class);
startActivity(intentBack);
}
});
Button buttonSalve = (Button) findViewById(R.id.buttonSave);
buttonSalve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Credit_Card credit_card = helper.takeCreditCard();
Credit_CardDAO dao = new Credit_CardDAO(AddCreditCardActivity.this);
if(credit_card.getId_Credit_Card() != null){
dao.edit(credit_card);
}else {
dao.infix(credit_card);
}
dao.close();
Intent intentSalve = new Intent(AddCreditCardActivity.this, UserPaymentsActivity.class);
startActivity(intentSalve);
Toast.makeText(AddCreditCardActivity.this, "Cartão de credito salvo", Toast.LENGTH_SHORT).show();
}
});
Intent intent = getIntent();
Credit_Card credit_Card = (Credit_Card) intent.getSerializableExtra("credit_card");
if (credit_Card != null){
helper.fillCreditCard(credit_Card);
}
}
}
Caso necessite de alguma outra informação só falar.