I’m trying to do search which include images and textview.
So when I search it returns the positive result, but when i go back and search with other value it returns the old return and new result at the same time.
I want my listView not to add old data into it. I need to over write the old data with a new value. here my code :
public void onClick(View Kv) {
Intent moreDetailsIntent = new Intent(MainMenu.this,ListMobileActivity.class);
Bundle dataBundle = new Bundle();
dataBundle.putString("Prov","KwaZulu-Natal");
moreDetailsIntent.putExtras(dataBundle);
startActivity(moreDetailsIntent);
});
B_GP.setOnClickListener(new View .OnClickListener() {
@Override
public void onClick(View Gv) {
Intent moreDetailsIntent = new Intent(MainMenu.this,ListMobileActivity.class);
Bundle dataBundle = new Bundle();
dataBundle.putString("Prov","Gauteng");
moreDetailsIntent.putExtras(dataBundle);
startActivity(moreDetailsIntent);
}
});
When i click a first buttonKZN it must display all KZN provinces and when click buttonB_GP it must return all GP province. so what it does it just return the old data when i search for the second time, here my listView classess :
Bundle b = getIntent().getExtras(); // Getting the Bundle object that pass from another activity
String SelectedProv = b.getString("Prov");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("ProvinceName",SelectedProv));
Log.d("ProvinceName",SelectedProv);
JSONObject json = jsonParser.makeHttpRequest("http://10.0.2.2/php/searchKZN.php", "POST", params);
try{
JSONArray earthquakes = json.getJSONArray("PROV");
for(int i=0;i<earthquakes.length();i++){
JSONObject e = earthquakes.getJSONObject(i);
String PCity = e.getString("P_City");
PNames.add(PCity);
String Pimage = e.getString("Pname");
PImages.add(Pimage);
}
} catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
setListAdapter(new MobileArrayAdapter(this, PNames,PImages));
So please help me to diplay the correct values according to selected button.
try this
PNames.clear(), PImages.clear();before