I am getting id from previous activity,if id is null then i parse data and store it in arraylist,but if it is not null then i dont parse data and trying to set arraylist in listview,but it shows arraylist null
mRecyclerView = (ListView) findViewById(R.id.filter_orderlist);
makeJsonArrayRequestCountry();
}
private void makeJsonArrayRequestCountry() {
showpDialog();
JsonArrayRequest req = new JsonArrayRequest( filter_url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("ress", response.toString());
filterList =new ArrayList<FilterModelClass>();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
String heder=obj.getString("filterName");
System.out.println("Hader"+heder);
JSONArray details=obj.getJSONArray("getParam");
for(int j=0;j<details.length();j++)
{
JSONObject det=details.getJSONObject(j);
FilterModelClass movie = new FilterModelClass();
movie.setFilter_Name(det.getString("paramName"));
String cityid=movie.setFilter_ID(det.getString("paramId"));
filterList.add(movie);
}
mAdapter = new MyCustomBaseAdapter(FilterListActivity.this,filterList);
mRecyclerView.setAdapter(mAdapter);
btnSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = "";
List<FilterModelClass> stList = ((MyCustomBaseAdapter) mAdapter)
.getStudentist();
for (int i = 0; i < stList.size(); i++) {
FilterModelClass singleStudent = stList.get(i);
if (singleStudent.isselected() == true) {
data = data+singleStudent.getFilter_ID().toString()+",";
}
}
Intent intent=new Intent();
intent.putExtra("filterid",data);
setResult(RESULT_OK, intent);
FilterListActivity.this.finish();
Toast.makeText(FilterListActivity.this,
"Selected Students:" + data, Toast.LENGTH_LONG)
.show();
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
hidepDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("ErrorVolley", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
hidepDialog();
}
});
MyApplication.getInstance().addToReqQueue(req, "jreq");
}
private void showpDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
private void hidepDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
default:
break;
}
}
public class MyCustomBaseAdapter extends BaseAdapter {
private List<FilterModelClass> searchArrayList;
ViewHolder holder;
private LayoutInflater mInflater;
SharedPreferences.Editor editor;
Context context;
public MyCustomBaseAdapter(Context mainActivity, List<FilterModelClass> results) {
context = mainActivity;
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
SharedPreferences sharedPrefs = context.getSharedPreferences("sharedPrefs", Context.MODE_PRIVATE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.sorting_items, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.tvName);
holder.cB = (CheckBox)convertView.findViewById(R.id.chkSelected);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
editor = sharedPrefs.edit();
holder.txtName.setText(searchArrayList.get(position).getFilter_Name());
holder.cB.setChecked(sharedPrefs.getBoolean("CheckValue" + position, false));
holder.cB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
editor.putBoolean("CheckValue" + position, isChecked);
editor.commit();
}});
return convertView;
}
class ViewHolder {
TextView txtName;
CheckBox cB;
}
public List<FilterModelClass> getStudentist() {
return searchArrayList;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…