I am trying to perform a search in a listview. Listview gets all info from db and displays them. The problem is that ArrayAdapter of search has a conflict with ListAdapter of listview. Because search doesn't work if it's performed before ListAdapter then if I place it below ListAdapter search works but on the other page arne't displayed other informations.
private void updateList() {
ListView lv = getListView();
Set<String> unionSet = new HashSet<String>();
for (HashMap<String, String> hashMap : mPlatesList) {
for(String key : hashMap.keySet())
if(key.equals(TAG_TARGA))
unionSet.add(hashMap.get(key));
}
String[] table = unionSet.toArray(new String[unionSet.size()]);
inputSearch = (EditText) findViewById (R.id.searchText);
myAdapter = new ArrayAdapter<String>(this, R.layout.plates_search, R.id.plates_search, table);
lv.setAdapter(myAdapter);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
Lista.this.myAdapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
ListAdapter adapter = new SimpleAdapter(this, mPlatesList,
R.layout.plates, new String[] { TAG_TARGA, TAG_NGJYRA, TAG_MARKA, TAG_SIGURACION, TAG_GJOBA, TAG_PRONAR, TAG_SGS },
new int[] { R.id.title, R.id.ngjyra, R.id.marka, R.id.siguracion, R.id.gjoba, R.id.pronar, R.id.sgs});
setListAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String targa = ((TextView)view.findViewById(R.id.title)).getText().toString();
String ngjyra = ((TextView)view.findViewById(R.id.ngjyra)).getText().toString();
String marka = ((TextView)view.findViewById(R.id.marka)).getText().toString();
String siguracion = ((TextView)view.findViewById(R.id.siguracion)).getText().toString();
String gjoba = ((TextView)view.findViewById(R.id.gjoba)).getText().toString();
String sgs = ((TextView)view.findViewById(R.id.sgs)).getText().toString();
String pronar = ((TextView)view.findViewById(R.id.pronar)).getText().toString();
String username = getIntent().getExtras().getString("Username");
Intent intent = new Intent(Lista.this,Info.class);
intent.putExtra("Targa",targa);
intent.putExtra("Ngjyra",ngjyra);
intent.putExtra("Marka",marka);
intent.putExtra("Gjoba",gjoba);
intent.putExtra("Siguracion",siguracion);
intent.putExtra("Sgs",sgs);
intent.putExtra("Pronar",pronar);
intent.putExtra("Username",username);
startActivity(intent);
}
});
}
The problem is that R.id.title, R.id.ngjyra, R.id.marka, R.id.siguracion, R.id.gjoba, R.id.pronar, R.id.sgs
that are displayed on the other page are empty if search is above ListAdapter otherwise info on the other page are displayed but search doesn't works. What to do?