Respectable Gurus Bellow code return wrong position and data by clicking on listview filtered Item of ArrayAdapter, Any Suggestion will by highly appreciated. Listview easily and perfectly filtered but it returns Wrong position. Any Suggestion will by highly appreciated.
public class MyActivity extends
AppCompatActivity {
---------Variables------
ArrayAdapter<String> adapter;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview_main);
Intent i = getIntent();
name2=i.getStringExtra("chiled");
postion = i.getIntExtra("id",0);
chiled= i.getStringExtra("name").replace(" ", "_");
//-------------------------Action Bar-------
ActionBar mActionBar = getSupportActionBar();
if (mActionBar != null) {
----Action BarCode---------
}
adapter = new ArrayAdapter<String>(MyActivity.this,
R.layout.listview_item,R.id.text);
//################# FireBaseStarts
mProgressDialog = new ProgressDialog(MyActivity.this);
mProgressDialog.setTitle("Loading List...");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
FirebaseDatabase database = FirebaseDatabase.getInstance();
myRef = database.getReference(chiled);
listview = (ListView) findViewById(R.id.listview);
queryRef = myRef.orderByChild("order");
queryRef.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long b = dataSnapshot.getChildrenCount();
imageUrls = new String[(int) b];
int i = 0;
for (DataSnapshot ddataSnapshot : dataSnapshot.getChildren()) {
Object value = ddataSnapshot.getValue();
adapter.add(((Map) value).get("name").toString());
imageUrls[i] = ((Map) value).get("url").toString();
i++;
}
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();
mProgressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w("Database Error is: ", "loadPost:onCancelled", databaseError.toException());
Toast.makeText(MyActivity.this, "Failed to load post.",
Toast.LENGTH_SHORT).show();
}
});
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(MyActivity.this,
SecondActivity.class);
i.putExtra("name", adapter.getItem(position));
i.putExtra("id", position);
startActivity(i);
}
});
}
//---------------Search Starts
@Override
public boolean onCreateOptionsMenu(Menu
menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu,menu);
final MenuItem
item=menu.findItem(R.id.inputSearch);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setQueryHint("Search Naghma...");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
return true;
}}
Whenever I click on filtered Item on a listview populated by an simple ArrayAdapter , It returns Wrong position and data (Returns Old/original populated Listview Position and list Item). Please help I am googling about a weak.