title: Populate a ListView with content using SharedPreference
body: <p>Basically I have this <code>ListView</code> in an Activity and I want to send the row context when I press an <code>ImageButton</code> (the star).</p>
  
  <p>In the  Adapter class for the 1st list (<code>AdapterExploreListView</code>), I override the <code>OnClicklistener</code> for the <code>ImageButton</code> and I use a <code>SharedPreference</code> to transfer the content to the 2nd list from the 2nd activity.</p>
  
  <p>In my 2nd activity i tried generate a new <code>ListView</code> with data from the 1st activity. Here is my problem:</p>
  
  <p><strong>1st list:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/6lD8j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6lD8j.png" alt=""></a></p>
  
  <p><strong>1st adapter:</strong></p>
  
  <pre><code>public class AdapterExploreListView extends BaseAdapter implements Filterable {
      ArrayList&lt;Track&gt; tracks;
      Context context;
      private ArrayList&lt;Track&gt; items;
      private ArrayList&lt;Track&gt; orig;
      public static final String Title = "titleKey";
      public static final String Username = "usernameKey";
  
      public AdapterExploreListView(Context context, ArrayList&lt;Track&gt; tracks) {
          this.tracks = new ArrayList&lt;&gt;();
          this.tracks = tracks;
          this.context = context;
          getFilter();
      }
  
      @Override
      public int getCount() {
          return tracks.size();
      }
  
      @Override
      public Object getItem(int i) {
          return null;
      }
  
      @Override
      public long getItemId(int i) {
          return 0;
      }
  
      @Override
      public View getView(int i, View view, ViewGroup viewGroup) {
          View rowView = view;
          // reuse views
          if (rowView == null) {
              LayoutInflater inflater = LayoutInflater.from(context);
              rowView = inflater.inflate(R.layout.row_list_explore, null);
              // configure view holder
              ViewHolder viewHolder = new ViewHolder();
              viewHolder.title = (TextView) rowView.findViewById(R.id.titleTextView);
              viewHolder.userName = (TextView) rowView.findViewById(R.id.userNameTextView);
              viewHolder.listImageView = (ImageView) rowView.findViewById(R.id.favbutton);
              rowView.setTag(viewHolder);
          }
          // fill data
          final ViewHolder holder = (ViewHolder) rowView.getTag();
          Track track = tracks.get(i);
          holder.title.setText(track.getTitle());
          holder.userName.setText(track.getUsername());
          holder.listImageView.setImageResource(R.drawable.favoritespic);
          holder.listImageView.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(context,ForthActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  context.startActivity(intent);
                  SharedPreferences sp = context.getSharedPreferences("Save",
                      Context.MODE_PRIVATE);
                  SharedPreferences.Editor editor = sp.edit();
  
                  String n = holder.title.getText().toString();
                  String e = holder.userName.getText().toString();
                  editor.putString(Title, n);
                  editor.putString(Username, e);
                  editor.commit();
              }
          });
          //  if(!track.getArtworkUrl().equalsIgnoreCase("null"))
          //  {
          //      ImageLoader.getInstance().displayImage(track.getArtworkUrl(), holder.listImageView);
          //  } else {
          //      ImageLoader.getInstance().displayImage(track.getAvatarUrl(), holder.listImageView);
          //  }
          return rowView;
      }
  
      static class ViewHolder {
          TextView title;
          TextView userName;
          ImageView listImageView;
      }
  
      public Filter getFilter() {
          return new Filter() {
              @Override
              protected FilterResults performFiltering(CharSequence constraint) {
                  final FilterResults oReturn = new FilterResults();
                  final ArrayList&lt;Track&gt; results = new ArrayList&lt;Track&gt;();
                  if (orig == null) orig = items;
                  if (constraint != null) {
                      if (orig != null &amp;&amp; orig.size() &gt; 0) {
                          for (final Track g : orig) {
                              if (g.getTitle().toLowerCase().contains(constraint.toString()))
                                  results.add(g);
                          }
                      }
                      oReturn.values = results;
                  }
                  return oReturn;
              }
  
              @SuppressWarnings("unchecked")
              @Override
              protected void publishResults(CharSequence constraint,
                                            FilterResults results) {
                  items = (ArrayList&lt;Track&gt;) results.values;
                  notifyDataSetChanged();
              }
          };
      }
  
      public void notifyDataSetChanged() {
          super.notifyDataSetChanged();
          boolean notifyDataSetChanged = true;
      }
  }
  </code></pre>
  
  <p><strong>2nd adapter:</strong></p>
  
  <pre><code>public class AdapterExploreListView2 extends BaseAdapter {
      private ArrayList&lt;CustomObject&gt; objects;
      Context context;
  
      public static final String Title = "titleKey";
      public static final String Username = "usernameKey";
  
      public AdapterExploreListView2(Context context, ArrayList&lt;CustomObject&gt; objects) {
          this.objects = new ArrayList&lt;&gt;();
          this.objects = objects;
          this.context = context;
      }
  
      @Override
      public int getCount() {
          return objects.size();
      }
  
      public CustomObject getItem(int position) {
          return objects.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View view, ViewGroup viewGroup) {
          View rowView = view;
          // reuse views
          if (rowView == null) {
              LayoutInflater inflater = LayoutInflater.from(context);
              rowView = inflater.inflate(R.layout.row_list_forthact, null);
              // configure view holder
              ViewHolder viewHolder = new ViewHolder();
              viewHolder.title = (TextView) rowView.findViewById(R.id.titleTV);
              viewHolder.userName = (TextView) rowView.findViewById(R.id.userNameTV);
              // viewHolder.listImageView = (ImageView) rowView.findViewById(R.id.listImageView);
              rowView.setTag(viewHolder);
          }
          // fill data
          ViewHolder holder = (ViewHolder) rowView.getTag();
          holder.title.setText(objects.get(position).getProp1());
          holder.userName.setText(objects.get(position).getProp2());
          return rowView;
      }
  
      static class ViewHolder {
          TextView title;
          TextView userName;
          // ImageView listImageView;
      }
  
      public void notifyDataSetChanged() {
          super.notifyDataSetChanged();
          boolean notifyDataSetChanged = true;
      }
  }
  </code></pre>
  
  <p><strong>2nd activity:</strong></p>
  
  <pre><code>public class ForthActivity extends Activity {
      SharedPreferences sharedpreferences;
      public static final String Title = "titleKey";
      public static final String Username = "usernameKey";
      CustomObject obj;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.forthact);
          // title = (TextView) findViewById(R.id.etitle);
          // username = (TextView) findViewById(R.id.eemail);
          sharedpreferences = getSharedPreferences("Save",
             Context.MODE_PRIVATE);
  
          if (sharedpreferences.contains(Title)) {
              obj.setProp1(sharedpreferences.getString(Title, ""));
          }
          if (sharedpreferences.contains(Username)) {
              obj.setProp2(sharedpreferences.getString(Username, ""));
          }
  
          ArrayList&lt;CustomObject&gt; object = new ArrayList&lt;CustomObject&gt;();
          AdapterExploreListView2 customAdapter = new AdapterExploreListView2(ForthActivity.this, object);
          ListView lv = (ListView) findViewById(R.id.forthlistview);
          lv.setAdapter(customAdapter);
      }
  }
  </code></pre>
  
  <p><strong>CustomObject class:</strong></p>
  
  <pre><code>public class CustomObject {
      private String prop1;
      private String prop2;
  
      public CustomObject(String prop1, String prop2) {
          this.prop1 = prop1;
          this.prop2 = prop2;
      }
  
      public void setProp1(String prop1) {
          this.prop1 = prop1;
      }
  
      public void setProp2(String prop2) {
          this.prop2 = prop2;
      }
  
      public String getProp1() {
          return prop1;
      }
  
      public String getProp2() {
          return prop2;
      }
  }
  </code></pre>