List view not refreshed after filtering and array adapter in Android - Please help
<p>I created one list view, and arrayadapter now when i filter the arrayadpter its filtering the data perfect. But the listview is not refreshed :( it shows the previous data only.</p>

<p>My coding is as follows:</p>

<ol>
<li><p>TextView used inside ListView:
A Simple text view for displaying each row of list view</p></li>
<li><p>ListView : here there is a textview for search bar and a list view where I am using above textview.</p></li>
<li><p>onCreate method of Activity Here seachCountry is the textbox in above xml to search (filter) the countries.</p>

<pre><code>countryList = (ListView) findViewById(R.id.countryList);
searchCountry = (EditText) findViewById(R.id.search);
createProfile = (Button) findViewById(R.id.createProfile);      
countries = getResources().getStringArray(R.array.countries_array);     
//countryArray = new ArrayAdapter&lt;String&gt;(this,R.layout.country_list_row , countries);
countryArray = new CountryArrayAdapter&lt;String&gt;(this,R.layout.country_list_row , countries);
countryList.setAdapter(countryArray);       
countryList.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int position, long arg3) {
        countryFrom = ((TextView) view).getText().toString();               
    }
});

searchCountry.addTextChangedListener(new TextWatcher() {            
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {               
    }           
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {                
    }

    @Override
    public void afterTextChanged(Editable s) {
        SelectCountryActivity.this.countryArray.getFilter().filter(s);
        countryArray.notifyDataSetChanged();
    }
});

createProfile.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent i = new Intent(SelectCountryActivity.this,CreateProfileActivity.class);
        i.putExtra("countryFrom", countryFrom);
        startActivity(i);
        finish();
    }
});
</code></pre></li>
<li><p>ArrayList Adapter</p>

<p><code>public class CountryArrayAdapter extends ArrayAdapter{
    public String[]  allItems;
    public String[] subItems;
    private CountryFilter filter;</p>

<pre>public CountryArrayAdapter(Context context, int textViewResourceId, String[] countryList) {
    super(context, textViewResourceId, countryList);
    // TODO Auto-generated constructor stub
    this.subItems = countryList;
    this.allItems = this.subItems;
}

@Override
public Filter getFilter() {
    if (filter == null){
      filter  = new CountryFilter();
    }
    return filter;
  }

 @Override
 public int getCount() {
     return subItems.length;
 }

 @Override
 public String getItem(int position) {
     return subItems[position];
 }

 private class CountryFilter extends Filter{

    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
         FilterResults results = new FilterResults();
         ArrayList&lt;String&gt; i = new ArrayList&lt;String&gt;();
         String[] contents;

          if (constraint!= null &amp;&amp; constraint.toString().length() &gt; 0) {

              for (int index = 0; index &lt; allItems.length; index++) {
                  String si = allItems[index];
                  if(si.startsWith(constraint.toString())){
                    i.add(si);  
                  }
              }
              contents = new String[i.size()];
              i.toArray(contents);
              results.values = contents;
              results.count = contents.length;                   
          }
          else{
              synchronized (allItems){
                  results.values = allItems;
                  results.count = allItems.length;
              }
          }
          return results;
    }

    @Override
    protected void publishResults(CharSequence constraint,
            FilterResults results) {
        // TODO Auto-generated method stub
        subItems =  (String[])results.values;
        notifyDataSetChanged();
    }
}
</code></pre></li>
</ol>

<p>I come to know from some links that inflater will solve my problem but not able to figure it out that how to use inflater.</p>

<p>Please help me to solve the problem of refreshing the view part.</p>

<p>Thanks a lot in advance.</p>

<p>with best regards,
Ishan</p>
