title: Not able to display previous data in ListView in Android while using notifyDataSetChanged()?
body: <p>I am not able to display previous data displayed in ListView when using <code>notifyDataSetChanged()</code> method of adapter. Used String array (even tried <code>ArrayList&lt;String&gt;</code>) for storing data.  </p>
  
  <p>I have tried almost all answers relevant to this question but couldn't get the correct result. Any help will be appreciated.
  In my code I am trying to modify the String array.</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements View.OnClickListener{
  
      String countryArray[];
      Button add;
      CustomAdapter adapter;
      ListView list,newList;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          countryArray = new String[3];
          countryArray[0] = "India";
          countryArray[1] = "USA";
          countryArray[2] = "England";
          adapter = new CustomAdapter(this,android.R.layout.simple_list_item_1,countryArray);
          list = (ListView) findViewById(R.id.lvCheckList);
          newList = list;
          list.setAdapter(adapter);
          add = (Button) findViewById(R.id.bAdd);
          add.setOnClickListener(this);
      }
  
  
      @Override
      public void onClick(View v) {
          countryArray[2] = "belgium";
          adapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p><strong>CustomAdapter</strong></p>
  
  <pre><code>public class CustomAdapter extends ArrayAdapter&lt;String&gt; {
  
      Context context;
      String[] values;
      View rowView;
  
      public CustomAdapter(Context context, int val, String[] objects) {
          super(context,val,objects);
          this.context = context;
          this.values = objects;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          if(convertView == null) {
              LayoutInflater inflater = (LayoutInflater)    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              rowView = inflater.inflate(R.layout.test, parent, false);
          }
          TextView tx = (TextView) rowView.findViewById(R.id.tv1);
          ImageView iv = (ImageView) rowView.findViewById(R.id.iv1);
          tx.setText(values[position]);
          iv.setImageResource(R.drawable.Image1);
          return rowView;
      }
  }
  </code></pre>