-1

Database Manager code

 public HouseHoldIncome getHoseHold(String id) {
    HouseHoldIncome listViewEditing = null;
    try {
        Dao<HouseHoldIncome, String> 
        householdIncomeDao =     dbHelper.getDaoHouseHoldIncome();
         listViewEditing= householdIncomeDao.queryForId(id);
    } catch (SQLException e) {
        Logger.get().e(GreenAgriApp.getInstance(), e.getMessage());
        e.printStackTrace();
    }
    return listViewEditing;
}

    Adapter class

  updatebutton=(Button)view.findViewById(R.id.Update);

  updatebutton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        update((int) v.getTag());
    }

    });


 public void update(int position)
 {
   HouseHoldIncome houseHoldIncome=arrayList.get(position);
   DatabaseManager.getInstance(mcontext)
 .getHoseHold(String.valueOf(position));
   arrayList.add(position,houseHoldIncome);
   notifyDataSetChanged();
  }

I am new to Android, I want to create an update view with pre populated data which has a form . I want to pass a custom object from update method to a fragment. How can I achieve this?

Vimesh Pk
  • 144
  • 1
  • 3
  • 8
  • It doesn't look like you've posted the code to your Fragment or the object that you need to pass into your Fragment. I'm a little confused what you are trying to accomplish. – Andrea Thacker Aug 14 '15 at 16:31

2 Answers2

1

A simple way is to create a public setter method on your Fragment that you can use to set data inside it.

Fragment

public class MyFragment extends Fragment {

    private CustomObject object;

    ...

    public void setCustomObject(CustomObject object){
        this.object = object;
    }

}

Creating Fragment with Data

CustomObject object = new CustomObject();

MyFragment fragment = new MyFragment();
fragment.setCustomObject(object);

Check out this question for more information.

Community
  • 1
  • 1
Andrea Thacker
  • 3,440
  • 1
  • 25
  • 37
0

You should make your custom object class serializable or parcelable which allows you to send data to fragments throught fragment's getArguments() method.

  1. make your class serializable or parcelable ( Prefer Parcelable as it is more effecient ).
  2. create a bundle and put your custom object using bundle.putParcelable() into bundle.

3.pass data to fragment by setting its argument using fragment.setArguments(Bundle) method.

4.Access your custom object from within the fragment using getArguments() method