I have successfully parsed JSON data into ListView using ArrayList, but unable to populate List based on City
name.
Like I am allowing user to select City and then l am trying to populate results into ListView using new ArrayList, but not getting any data into ListView.
public class TitleListActivity extends Activity {
....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_title);
......
new JSONAsyncTask().execute("http://murl.com/json/citywise.json");
try {
Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getString("new_variable_name");
Toast.makeText(TitleListActivity.this, value, Toast.LENGTH_LONG).show();
// not getting data city wise
cityWiseSearch();
}
else
{
// getting all data
adapter = new TitleListAdapter(TitleListActivity.this, R.layout.row, allArrayList);
listview.setAdapter(adapter);
}
} catch (Exception e) {
// TODO: handle exception
}
....
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(String... urls) {
try {
....
JSONArray jarray = jsono.getJSONArray("cities");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
destination = new TitleList();
destination.setTitle(object.getString("address"));
allArrayList.add(destination);
......
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
....
}
}
public void cityWiseSearch() {
for (int i = 0; i <allArrayList.size(); i++) {
destination = (TitleList) allArrayList.get(i);
String strStatuss = allArrayList.get(i).getCity();
if (strStatuss.equalsIgnoreCase(value)){
cityArrayList.add(destination);
}
}
adapter = new TitleListAdapter(TitleListActivity.this, R.layout.row, cityArrayList);
listview.setAdapter(adapter);
}
}