4
I was making an app for me kind of joking around and I came across a problem, the ListView
Android Studio does not ignore the accents of Portuguese.
Could someone post a code to fix this? Like do 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]);
}
}
}
}
}
Thanks for the tip buddy, I tried to copy and paste your code, but I am using API 8 and android studio tells me that Normalizer only works on API 9, even so thank you.
– wilfer
@wilfer hello. I edited the answer, see if it now works!
– rsicarelli
Hello, thanks again for the tip, sorry to be a bit boring, but as I said I’m just curious in programming, what would be the method to initialize the string "removeAcentosPreGingerbread", thanks in advance. PS: I am looking for books, videos and giving a study in android programming on the net, since I do not count on courses or something similar in my region.
– wilfer
@wilfer edited again. The code you quoted, is for checking the SDK installed on the device. Depending on the version, call the specific method for each one
– rsicarelli
Thanks a lot, @sicachester, it worked just fine. Valeuzaoo.
– wilfer