android ListActivity如何用Json Volley Library填充数据

时间:2016-07-05 10:46:42

标签: android android-volley

android ListActivity如何使用Custom Adapter getter setter,调用json Volley库填充数据ListActivity?无法用Json填充数据如何实现,请帮助我 我的代码

ItemFragment类

   <?php echo $form->field($model, 'region_id[]')->checkboxList($regs); ?> 

适配器类

public class ItemFragment extends ListActivity {
RequestParse requestParse;
MySharedPreferences prefs;
String UsrId;
Context context;
ArrayList<BizForumArticleInfo> list = new ArrayList<>();
private List<BizForumArticleInfo> CountryCodeNumber = new ArrayList<>();

MobileArrayAdapter adapter;
LinearLayoutManager mLayoutManager;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view_android_example);
    requestParse = new RequestParse();
    prefs = MySharedPreferences.getInstance(this, SESSION);
    UsrId = prefs.getString("UsrID", "");
    context = getApplicationContext();
    setListAdapter(new MobileArrayAdapter(this,0, list));

    getJson(60);
}

public void getJson(final int limit){
    requestParse.postJson(ConfigApi.postArticleBiz(), new RequestParse.VolleyCallBackPost() {
        @Override
        public void onSuccess(String result) {
            list = parseResponse(result);

        }
        @Override
        public void onRequestError(String errorMessage) {
        }
        @Override
        public Map OnParam(Map<String, String> params) {
            params.put("sessionid", UsrId);
            params.put("offset", "0");
            params.put("limit", String.valueOf(limit));
            params.put("viewtype", "all");
            params.put("access_token","e3774d357aa7d4bd14e9763b5459ee9cf7ebe36161c142551836ee510d98814a:b349b76b334a94b2");
            return params;
        }
    });
}
public static ArrayList<BizForumArticleInfo> parseResponse(String response) {
    ArrayList<BizForumArticleInfo> bizList = new ArrayList<>();
    try {
        JSONObject json = new JSONObject(response);
        JSONArray data = json.getJSONArray(DATA);
        for (int i = 0; i < data.length(); i++) {
            BizForumArticleInfo ls = new BizForumArticleInfo();
            JSONObject item = data.getJSONObject(i);
            String ArticleTitle = item.getString("ArticleTitle");
            String Article = item.getString("Article");
            M.i("===================",ArticleTitle);//working
            ls.setArticleTitle(ArticleTitle);
            ls.setArticleArticle(Article);
            bizList.add(ls);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return bizList;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    String selectedValue = (String) getListAdapter().getItem(position);
    Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
    Intent intent = new Intent();
    intent.putExtra("selectedValue", selectedValue);
    setResult(RESULT_OK, intent);
    finish();


    //startActivity(new Intent(v.getContext(), MainActivity.class));

}
}

0 个答案:

没有答案