I was making an application for me kind of in jest and I came across a problem, ListView
of Android Studio does not ignore the Portuguese accents.
Could anyone post a code, would you like to resolve this? Type the word search by ignoring the accents.
Follow the code I'm using below.
public class MainActivity extends ActionBarActivity {
private ListView lv;
private EditText et;
private String[] lst;
private ArrayList < String > lst_Encontrados = new ArrayList < String > ();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lvlist);
et = (EditText) findViewById(R.id.etlist);
lst = new String[] {
"Cáncer", "Cancer", "Mamá"
};
lv.setAdapter(new ArrayAdapter < String > (this, android.R.layout.simple_list_item_1, lst));
CarregarEncontrados();
et.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
CarregarEncontrados();
lv.setAdapter(new ArrayAdapter < String > (MainActivity.this, android.R.layout.simple_list_item_1, lst_Encontrados));
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Override
public void onItemClick(AdapterView <? > arg0, View view, int position, long id) {
AlertDialog.Builder test = new AlertDialog.Builder(MainActivity.this);
if (((TextView) view).getText().equals("Cáncer")) {
test.setTitle("hemoglobina");
test.setMessage("doidera");
test.setNeutralButton("OK", null);
test.show();
}
if (((TextView) view).getText().equals("Cancer")) {
test.setTitle("Volume");
test.setMessage("KCT");
test.setNeutralButton("OK", null);
test.show();
}
if (((TextView) view).getText().equals("Mamá")) {
test.setTitle("eu");
test.setMessage("sou fodastico");
test.setNeutralButton("OK", null);
test.show();;;
}
}
});
}
public void CarregarEncontrados() {
int textlength = et.getText().length();
lst_Encontrados.clear();
for (int i = 0; i < lst.length; i++) {
if (textlength <= lst[i].length()) {
if (et.getText().toString().equalsIgnoreCase((String) lst[i].subSequence(0, textlength))) {
lst_Encontrados.add(lst[i]);
}
}
}
}
}