I am working with SQLite Database, I want to check which button was clicked to show respective table row, for example 1st button corresponds to 1st row and so on. But the problem is, it never shows the table elements.
Here is the code that saves extra information about the button:
private View.OnClickListener btnListener = new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getActivity(), AddGoalActivity.class);
switch (view.getId()) {
case R.id.button:
intent.putExtra("called", 1);
startActivityForResult(intent, BUTTON_1);
break;
case R.id.button2:
intent.putExtra("called", 2);
startActivityForResult(intent, BUTTON_2);
break;
}
}
};
The code below checks which button started the activity and shows the table elements:
Bundle called_from = getIntent().getExtras();
if (called_from == null) {
return;
}
int called = called_from.getInt("called");
if (called == (1)){
Task t = dbHandler.getTask(1);
editText.setText(t.getTaskName());
spinner.setSelection(t.getStartMonth());
spinner2.setSelection(t.getEndMonth());
}
Aucun commentaire:
Enregistrer un commentaire