My autocompletexview connect with WebServices. When my autocompletextview load the dataset, for example:
Barcelona Sevilla Cádiz Castellon Madrid Castilleja Castilla
When I write "Ca" , only this options are available
Castellon Castilleja Castilla
This dont show accents words ( Cádiz).
Here is my code
public class MainActivity extends Activity {
InputStream is=null;
String result=null;
String line=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://www.aaaaaa.com/aaaaaa.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("Pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.e("Pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
try
{
JSONArray JA=new JSONArray(result);
JSONObject json= null;
final String[] str1 = new String[JA.length()];
for(int i=0;i<JA.length();i++)
{
json=JA.getJSONObject(i);
str1[i]=json.getString("nombre");
}
final AutoCompleteTextView text = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
final List<String> list = new ArrayList<String>();
for(int i=0;i<str1.length;i++)
{
list.add(str1[i]);
}
Collections.sort(list);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
(getApplicationContext(), android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
text.setThreshold(1);
text.setAdapter(dataAdapter);
text.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), list.get(arg2).toString(),
Toast.LENGTH_SHORT).show();
}
});
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
}
I would like to write the character "a" and get results that include the characters "a", "á", "â", ...
Thanks!
You have to create you custom adapter and include a custom Filter where you replace the accented characters by plain characters (á-a, é-e, í-i,...).
You can find a custom implementation here: Diacritics/international characters in AutoCompleteTextView. Pay special attention to the getFilter() method and the HRArrayFilter class (at the bottom of the code).