0

I am writing an Android application with a main page being a list of categories, and then beside each category there is an edit button.

When edit button is clicked, an entry form with the "category" properties filled up is supposed to be shown.

How to pass the category ID or name to the new created form so that it could load from database the properties of selected category

I have no issue with getting the selected category name, by using the code below:

public String getSelectedItem(View view) {
    LinearLayout vwParentRow = (LinearLayout) view.getParent();
    TextView child = (TextView) vwParentRow.getChildAt(0);
    return (String) child.getText();
}

//edit button clicked
public void editCategoryHandler(View view) {
    Intent i = new Intent(this, EntryCategory.class);
    startActivity(i);
}

2 Answers2

0

I am sure you have just passed String array or ArrayList to display inside that Category List, instead you should prepare an ArrayList of Category objects, and then whenever user clicked a particular item from a category list, get that object at that position after implementing OnItemClickListener, and then pass this received object to the desired activity.

In short, get object for a clicked item and then pass this object.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

To pass the value to a new activity, you have to use putExtra() and getExtra().

Please refer the following page

How to use putExtra() and getExtra() for string data

Community
  • 1
  • 1
Jomy John
  • 6,308
  • 4
  • 28
  • 32