rayList中查看通话notifyDataSetChanged

rayList中查看通话notifyDataSetChanged

本文介绍了如何在ArrayList中查看通话notifyDataSetChanged()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更新并保存后,结果页面打开ArrayList的页面。我想我需要以某种方式刷新,以便它反映在UI上的变化。我试着打电话给notifyDataSetChanged(),但没有运气与我的经验水平。可能有人亲切地说明如何实现它吗?

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.all_requests);    requestsList =新的ArrayList<&HashMap的LT;字符串,字符串>>();    新LoadAllRequests()执行();    ListView控件列表= getListView();    list.setOnItemClickListener(新OnItemClickListener(){        公共无效onItemClick(适配器视图<>母公司,观景,
                INT位置,长的id){            字符串REQUEST_ID =((的TextView)view.findViewById(R.id.request_id))的getText()的toString()。
            在意向=新意图(getApplicationContext()
                    ViewRequestActivity.class);            in.putExtra(TAG_ID,REQUEST_ID);
            startActivityForResult(在100);
        }
    });}//从ViewRequestActivity响应时删除请求重新加载该页面@覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,结果code,数据);
    //如果结果code 100
    如果(结果code == 100){
        意向意图= getIntent();
        完();
        startActivity(意向);
    }}
类LoadAllRequests扩展的AsyncTask<字符串,字符串,字符串> {    保护字符串doInBackground(字符串参数... args){        清单<&的NameValuePair GT; PARAMS =新的ArrayList<&的NameValuePair GT;();        JSONObject的JSON = jParser.makeHtt prequest(url_all_requests,GET,则params);
        Log.d(所有要求:json.toString());        尝试{            INT成功= json.getInt(TAG_SUCCESS);            如果(成功== 1){
                请求= json.getJSONArray(TAG_REQUESTS);
                的for(int i = 0; I< requests.length();我++){
                    JSONObject的C = requests.getJSONObject(I)
                    字符串REQUEST_ID = c.getString(TAG_ID);
                    字符串request_title = c.getString(TAG_TITLE);
                    HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();                    //将每个子节点的HashMap键=>值
                    map.put(TAG_ID,REQUEST_ID);
                    map.put(TAG_TITLE,request_title);
                    requestsList.add(地图);
                }
            }其他{
                意图I =新意图(getApplicationContext()
                        NewRequestActivity.class);                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(ⅰ);
            }
        }赶上(JSONException E){
            e.printStackTrace();
        }        返回null;
    }


解决方案

您需要为您的ListView的适配器。该适配器用于显示什么饲料数据到它。我建议你​​通过本教程阅读:

所以,一旦你已经创建了适配器,然后叫 lv.setAdapter(小于适配器>),你可以调用<适配器> .notifyDataSetChanged()。这将告诉它需要刷新自己的适配器。

This is the ArrayList page that opens as a result page after update and save. I guess I would need to somehow refresh so that it reflects the changes on the UI. I've tried to call notifyDataSetChanged() but no luck with my level of experience. Could someone kindly show how to implement it please?

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_requests);

    requestsList = new ArrayList<HashMap<String, String>>();

    new LoadAllRequests().execute();

    ListView list = getListView();

    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            String request_id = ((TextView) view.findViewById(R.id.request_id)).getText().toString();


            Intent in = new Intent(getApplicationContext(),
                    ViewRequestActivity.class);

            in.putExtra(TAG_ID, request_id);


            startActivityForResult(in, 100);
        }
    });

}

// Response from ViewRequestActivity when delete a request reload this page again

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if result code 100
    if (resultCode == 100) {
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }

}


class LoadAllRequests extends AsyncTask<String, String, String> {



    protected String doInBackground(String... args) {

        List<NameValuePair> params = new ArrayList<NameValuePair>();

        JSONObject json = jParser.makeHttpRequest(url_all_requests, "GET", params);


        Log.d("All Requests: ", json.toString());

        try {

            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {


                requests = json.getJSONArray(TAG_REQUESTS);


                for (int i = 0; i < requests.length(); i++) {
                    JSONObject c = requests.getJSONObject(i);


                    String request_id = c.getString(TAG_ID);
                    String request_title = c.getString(TAG_TITLE);


                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_ID, request_id);
                    map.put(TAG_TITLE, request_title);


                    requestsList.add(map);
                }
            } else {


                Intent i = new Intent(getApplicationContext(),
                        NewRequestActivity.class);

                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
解决方案

You need to create an adapter for your ListView. The adapter is what feeds data to it for displaying. I would recommend you reading through this tutorial:

http://www.vogella.com/articles/AndroidListView/article.html

So once you have created your adapter and then called lv.setAdapter(<adapter>), you can then call <adapter>.notifyDataSetChanged(). This will tell the adapter that it needs to refresh itself.

这篇关于如何在ArrayList中查看通话notifyDataSetChanged()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:00