@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { profile = inflater.inflate(R.layout.profile_layout, container, false); editbtn = (Button) profile.findViewById(R.id.edit); listView = (ListView) profile.findViewById(R.id.profileList); data = getActivity().getSharedPreferences(mypreference, Context.MODE_PRIVATE); if (data.contains(TASKS)) { LoadPreferences(); } // Picking Profile picture imageProfile = (ImageView) profile.findViewById(R.id.profilePic); imageCompany = (ImageView) profile.findViewById(R.id.btn_pick); // image listeners imageCompany.setOnClickListener(this); imageProfile.setOnClickListener(this); profilebtn = (Button) profile.findViewById(R.id.profilebtn); referralbtn = (Button) profile.findViewById(R.id.referralbtn); vzfrndsbtn = (Button) profile.findViewById(R.id.vzfrnds); label = new ArrayList<String>(); label.add("Fname"); label.add("Lname"); label.add("Industry"); label.add("Company"); label.add("Address"); values = new ArrayList<String>(); values.add("veena"); values.add("M"); values.add("IT"); values.add("BITJIN"); values.add("GIT"); for (int i = 0; i < label.size(); i++) { ListItem item = new ListItem(); item.setLabel(label.get(i)); item.setValue(values.get(i)); arrayList.add(item); } editbtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (clickCount == 0) { editbtn.setText("Save"); editTextAdapter.actv(true); editTextAdapter.notifyDataSetChanged(); // listView.setAdapter(editTextAdapter); // LoadPreferences(); // Log.e("selected position of textview", "" + position); Toast.makeText(getActivity(), "click 0", Toast.LENGTH_LONG).show(); clickCount = 1; } else if (clickCount == 1) { editbtn.setText("Edit"); editTextAdapter.actv(false); json2 = new Gson().toJson(groupItem); // updated array SavePreferences(TASKS, json2); LoadPreferences(); editTextAdapter.notifyDataSetChanged(); // listView.setAdapter(editTextAdapter); Toast.makeText(getActivity(), "click 1", Toast.LENGTH_LONG).show(); clickCount = 0; } } }); if (!groupItem.isEmpty()) json2 = new Gson().toJson(groupItem); // updated array Log.e("updated array", "" + json2); json = new Gson().toJson(arrayList); // default array // converting arrayList to json to Save the values in sharedpreference by calling SavePrefernces // Check if the updated array is equal to default array if false load default array else load // updated array if (json.equals(json2) || json2 == null) { SavePreferences(TASKS, json); } else { SavePreferences(TASKS, json2); } LoadPreferences(); vzfrndsbtn.setOnClickListener(this); referralbtn.setOnClickListener(this); return profile; }