【问题标题】:how to update Expandable Listview with new items?(notifyDataSetChanged()not works)如何使用新项目更新可扩展列表视图?(notifyDataSetChanged()不起作用)
【发布时间】:2017-04-14 07:24:13
【问题描述】:

我有可扩展的 Lisview,我将数据从服务器加载到 listview。

还有一些带有edittext的行。所以每当我按下右键进行编辑时, edittext 可聚焦并编辑该值并再次按下该按钮值将转到服务器。

但是从这里它并没有保存它,它又恢复了原来的价值。 但是当我刷新相同的活动值时发生了变化。

如何使用新的可编辑值加载可扩展列表视图?

这是我的代码:-这是我的活动

public class EditSwitch1Activity extends AppCompatActivity {


ExpandableListAdapter1 listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
SharedPreferences pref;
SharedPreferences.Editor editor;
private TextView edit_text;
HashMap<String, List<String>> listDataChild;
private TextView back;
private String roomId;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_editswitch1);
    pref = PreferenceManager.getDefaultSharedPreferences(EditSwitch1Activity.this);
    editor = pref.edit();
    expListView = (ExpandableListView) findViewById(R.id.lvExp);

    back = (TextView) findViewById(R.id.back);
    expListView.setItemsCanFocus(true);
    // preparing list data

    Window window = EditSwitch1Activity.this.getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(EditSwitch1Activity.this.getResources().getColor(R.color.color_statusbar));


    roomId = getIntent().getStringExtra("roomId");
    String serverURL = "http://dashboard.droidhomes.in/api/module?room_id=" + roomId;

    // Use AsyncTask execute Method To Prevent ANR11 Problem
    new LongOperation1().execute(serverURL);


    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();


    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });


}

private class LongOperation1 extends AsyncTask<String, Void, Void> {

    // Required initialization

    // private final HttpClient Client = new DefaultHttpClient();
    private String Content;
    private String Error = null;

    private ProgressDialog Dialog = new ProgressDialog(
            EditSwitch1Activity.this);
    String data = "";

    protected void onPreExecute() {
        // NOTE: You can call UI Element here.

        //Dialog.setMessage("Please wait..");
        //Dialog.show();

        //         data += "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA";
    }

    // Call after onPreExecute method
    protected Void doInBackground(String... urls) {

        /************ Make Post Call To Web Server ***********/
        BufferedReader reader = null;
        // final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
        // String urlEncoded = Uri.encode(path, ALLOWED_URI_CHARS);
        // Send data
        try {

            // Defined URL where to send data

            URL url = new URL(urls[0]);

            // Send POST data request

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //conn.setDoOutput(true);
            String auth_token = pref.getString("auth_token", "");

            conn.setRequestProperty("Authorization", auth_token);
            //conn.setRequestMethod("GET");

            //byte[] encodedPassword = ( "Authorization" + ":" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA" ).getBytes();
            //BASE64Encoder encoder = new BASE64Encoder();

            // Get the server response

            reader = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line = null;

            // Read Server Response
            while ((line = reader.readLine()) != null) {
                // Append server response in string
                sb.append(line + "\n");
            }

            // Append Server Response To Content String
            Content = sb.toString();
        } catch (Exception ex) {
            Error = ex.getMessage();
        } finally {
            try {

                reader.close();
            } catch (Exception ex) {
            }
        }

        /*****************************************************/
        return null;
    }

    protected void onPostExecute(Void unused) {
        // NOTE: You can call UI Element here.

        // Close progress dialog
        // Content=Content.replaceAll("<string>","");
        // Content=Content.replaceAll("</string>", "");
        Dialog.dismiss();

        if (Error != null) {

            Toast toast = Toast.makeText(getApplicationContext(),
                    "Bad request", Toast.LENGTH_LONG);
            toast.show();
            // uiUpdate.setText("Output : " + Error);

        } else {

            // Show Response Json On Screen (activity)
            // uiUpdate.setText(Content);

            /****************** Start Parse Response JSON Data *************/

            // String OutputData = "";
            // JSONObject jsonResponse;

            Gson gson = new Gson();
            // Map messageObjMap = new Gson().fromJson(Content, Map.class);
            // String type = messageObjMap.get("messageType").toString();

            // Song song = gson.fromJson(message, Song.class);

            final SearchResponse response = gson.fromJson(Content,
                    SearchResponse.class);

            if (response.getStatus() == true) {


                List<String> newlist = new ArrayList<String>();


                for (int i = 0; i < response.getModule().length; i++) {


                    listDataHeader.add(response.getModule()[i].getModule_name());
                    newlist = new ArrayList<String>();
                    for (int j = 0; j < response.getModule()[i].getNo_of_switches(); j++) {

                        if (response.getModule()[i].getModuleId().getModuleid().equals(response.getModule()[i].getSwitches()[j].getModuleId().getModuleid())) {


                            newlist.add(response.getModule()[i].getSwitches()[j].getSwitch_name());


                        }


                        listDataChild.put(response.getModule()[i].getModule_name(), newlist);


                    }


                }


                listAdapter = new ExpandableListAdapter1(EditSwitch1Activity.this, listDataHeader, listDataChild, response);

                // setting list adapter
                expListView.setAdapter(listAdapter);
                listAdapter.notifyDataSetChanged();


            } else {

                Toast.makeText(getApplicationContext(), "status:-" + response.getStatus(), Toast.LENGTH_SHORT).show();
            }


        }

    }

}


@Override
protected void onResume() {
    super.onResume();

}

}

还附加了可扩展的列表视图适配器:-

public class ExpandableListAdapter1 extends BaseExpandableListAdapter {

private String childText;
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
private ArrayList<String> newlist;
private ArrayList<String> newlist1;
ArrayList<String>list1;
private SearchResponse response;
private Boolean onclick = true;

public ExpandableListAdapter1(Context context, List<String> listDataHeader,
                              HashMap<String, List<String>> listChildData, SearchResponse response) {
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
    this.response = response;


}

@Override
public Object getChild(int groupPosition, int childPosititon) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .get(childPosititon);
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
}

@Override
public View getChildView(final int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    childText = (String) getChild(groupPosition, childPosition);
    final ViewHolder holder;
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.txtListChild.setText(childText); // Here whatever you will type in edittext will be overwritten by the value of 'childText.getTotal'. So after you are done writing in edit text make sore you change that in "_listDataChild" list.


    newlist = new ArrayList<String>();
    newlist1 = new ArrayList<String>();
    list1=new ArrayList<>();
    list1.add(childText);
    final TextView txtListChild1 = (TextView) convertView
            .findViewById(R.id.flash1);





    txtListChild1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            if (onclick) {

                txtListChild1.setText("Save");
                holder.txtListChild.setEnabled(true);
                onclick = false;
            } else {

                //  ArrayList<String> itemList=new ArrayList<String>();
                //itemList.add();
                onclick = true;
                txtListChild1.setText("Edit");
                holder.txtListChild.setEnabled(false);
                newlist.add(response.getModule()[groupPosition].getSwitches()[childPosition].getSwitchId().getId());
                newlist1.add(holder.txtListChild.getText().toString());
                String url = "http://dashboard.droidhomes.in/api/switch";
                RequestQueue requestQueue = Volley.newRequestQueue(_context);
                JSONObject dataObj = new JSONObject();
                try {

                    JSONArray cartItemsArray = new JSONArray();
                    JSONObject cartItemsObjedct;
                    for(int i=0;i<newlist.size();i++){

                        cartItemsObjedct = new JSONObject();
                        cartItemsObjedct.putOpt("switch_id", newlist.get(i));
                        cartItemsObjedct.putOpt("switch_name",newlist1.get(i));
                        cartItemsArray.put(cartItemsObjedct);


                    }

                    dataObj.put("update_list", cartItemsArray);


                    JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(Request.Method.PUT, url, dataObj, new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            try {
                                Toast.makeText(_context, response.getString("status"), Toast.LENGTH_SHORT).show();
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            //mTextView.setText(error.toString());
                        }
                    }) {
                        @Override
                        public Map<String, String> getHeaders() throws AuthFailureError {
                            Map<String, String> headers = new HashMap<>();
                            headers.put("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA");
                            headers.put("Content-Type", "application/json");
                            return headers;
                        }
                    };
                    requestQueue.add(jsonArrayRequest);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            }


        }
    });

    notifyDataSetChanged();

    return convertView;

}

@Override
public int getChildrenCount(int groupPosition) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .size();
}

@Override
public Object getGroup(int groupPosition) {
    return this._listDataHeader.get(groupPosition);
}

@Override
public int getGroupCount() {
    return this._listDataHeader.size();
}

@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_group, null);
    }

    TextView lblListHeader = (TextView) convertView
            .findViewById(R.id.lblListHeader);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(headerTitle);

    return convertView;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

class ViewHolder {
    EditText txtListChild;

    public ViewHolder(View v) {
        txtListChild = (EditText) v.findViewById(R.id.lblListItem);
    }
}

public HashMap<String,List<String>> gethashmap() {

    return _listDataChild;
}

}

在这里,在这个适配器中,我使用了从活动调用的 gethashmap() 方法,因此它加载了新数据,但不知道如何执行此操作。

【问题讨论】:

    标签: android android-edittext expandablelistview


    【解决方案1】:

    用以下修改后的代码替换您的代码:

            public class EditSwitch1Activity extends AppCompatActivity {
    
    
        ExpandableListAdapter1 listAdapter;
        ExpandableListView expListView;
        List<String> listDataHeader;
        SharedPreferences pref;
        SharedPreferences.Editor editor;
        private TextView edit_text;
        HashMap<String, List<String>> listDataChild;
        private TextView back;
        private String roomId;
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
    
            setContentView(R.layout.activity_editswitch1);
            pref = PreferenceManager.getDefaultSharedPreferences(EditSwitch1Activity.this);
            editor = pref.edit();
            expListView = (ExpandableListView) findViewById(R.id.lvExp);
    
            back = (TextView) findViewById(R.id.back);
            expListView.setItemsCanFocus(true);
            // preparing list data
    
            Window window = EditSwitch1Activity.this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(EditSwitch1Activity.this.getResources().getColor(R.color.color_statusbar));
    
    
            roomId = getIntent().getStringExtra("roomId");
            String serverURL = "http://dashboard.droidhomes.in/api/module?room_id=" + roomId;
    
            // Use AsyncTask execute Method To Prevent ANR11 Problem
            new LongOperation1().execute(serverURL);
    
    
            listDataHeader = new ArrayList<String>();
            listDataChild = new HashMap<String, List<String>>();
    
            listAdapter = new ExpandableListAdapter1(EditSwitch1Activity.this, listDataHeader, listDataChild, response);
            // setting list adapter
            expListView.setAdapter(listAdapter);
    
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
    
    
        }
    
        private class LongOperation1 extends AsyncTask<String, Void, Void> {
    
            // Required initialization
    
            // private final HttpClient Client = new DefaultHttpClient();
            private String Content;
            private String Error = null;
    
            private ProgressDialog Dialog = new ProgressDialog(
                    EditSwitch1Activity.this);
            String data = "";
    
            protected void onPreExecute() {
                // NOTE: You can call UI Element here.
    
                //Dialog.setMessage("Please wait..");
                //Dialog.show();
    
                //         data += "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA";
            }
    
            // Call after onPreExecute method
            protected Void doInBackground(String... urls) {
    
                /************ Make Post Call To Web Server ***********/
                BufferedReader reader = null;
                // final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
                // String urlEncoded = Uri.encode(path, ALLOWED_URI_CHARS);
                // Send data
                try {
    
                    // Defined URL where to send data
    
                    URL url = new URL(urls[0]);
    
                    // Send POST data request
    
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    //conn.setDoOutput(true);
                    String auth_token = pref.getString("auth_token", "");
    
                    conn.setRequestProperty("Authorization", auth_token);
                    //conn.setRequestMethod("GET");
    
                    //byte[] encodedPassword = ( "Authorization" + ":" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA" ).getBytes();
                    //BASE64Encoder encoder = new BASE64Encoder();
    
                    // Get the server response
    
                    reader = new BufferedReader(new InputStreamReader(
                            conn.getInputStream()));
                    StringBuilder sb = new StringBuilder();
                    String line = null;
    
                    // Read Server Response
                    while ((line = reader.readLine()) != null) {
                        // Append server response in string
                        sb.append(line + "\n");
                    }
    
                    // Append Server Response To Content String
                    Content = sb.toString();
                } catch (Exception ex) {
                    Error = ex.getMessage();
                } finally {
                    try {
    
                        reader.close();
                    } catch (Exception ex) {
                    }
                }
    
                /*****************************************************/
                return null;
            }
    
            protected void onPostExecute(Void unused) {
                // NOTE: You can call UI Element here.
    
                // Close progress dialog
                // Content=Content.replaceAll("<string>","");
                // Content=Content.replaceAll("</string>", "");
                Dialog.dismiss();
    
                if (Error != null) {
    
                    Toast toast = Toast.makeText(getApplicationContext(),
                            "Bad request", Toast.LENGTH_LONG);
                    toast.show();
                    // uiUpdate.setText("Output : " + Error);
    
                } else {
    
                    // Show Response Json On Screen (activity)
                    // uiUpdate.setText(Content);
    
                    /****************** Start Parse Response JSON Data *************/
    
                    // String OutputData = "";
                    // JSONObject jsonResponse;
    
                    Gson gson = new Gson();
                    // Map messageObjMap = new Gson().fromJson(Content, Map.class);
                    // String type = messageObjMap.get("messageType").toString();
    
                    // Song song = gson.fromJson(message, Song.class);
    
                    final SearchResponse response = gson.fromJson(Content,
                            SearchResponse.class);
    
                    if (response.getStatus() == true) {
    
    
                        List<String> newlist = new ArrayList<String>();
    
                        listDataHeader.clear() ;
                        listDataChild.clear();
    
                        for (int i = 0; i < response.getModule().length; i++) {
    
    
                            listDataHeader.add(response.getModule()[i].getModule_name());
                            newlist = new ArrayList<String>();
                            for (int j = 0; j < response.getModule()[i].getNo_of_switches(); j++) {
    
                                if (response.getModule()[i].getModuleId().getModuleid().equals(response.getModule()[i].getSwitches()[j].getModuleId().getModuleid())) {
    
    
                                    newlist.add(response.getModule()[i].getSwitches()[j].getSwitch_name());
    
    
                                }
    
    
                                listDataChild.put(response.getModule()[i].getModule_name(), newlist);
    
    
                            }
    
    
                        }
    
    
                        //listAdapter = new ExpandableListAdapter1(EditSwitch1Activity.this, listDataHeader, listDataChild, response);
    
                        listAdapter.setListDataHeader(listDataHeader) ;
                        listAdapter.setListDataChild(listDataChild) ;
    listAdapter.setSearchResponse(response) ;
                        listAdapter.notifyDataSetChanged();
    
    
                    } else {
    
                        Toast.makeText(getApplicationContext(), "status:-" + response.getStatus(), Toast.LENGTH_SHORT).show();
                    }
    
    
                }
    
            }
    
        }
    
    
        @Override
        protected void onResume() {
            super.onResume();
    
        }
    

    适配器类

            public class ExpandableListAdapter1 extends BaseExpandableListAdapter {
    
        private String childText;
        private Context _context;
        private List<String> _listDataHeader; // header titles
        // child data in format of header title, child title
        private HashMap<String, List<String>> _listDataChild;
        private ArrayList<String> newlist;
        private ArrayList<String> newlist1;
        ArrayList<String>list1;
        private SearchResponse response;
        private Boolean onclick = true;
    
        public ExpandableListAdapter1(Context context, List<String> listDataHeader,
                                      HashMap<String, List<String>> listChildData, SearchResponse response) {
            this._context = context;
            this._listDataHeader = listDataHeader;
            this._listDataChild = listChildData;
            this.response = response;
    
    
        }
    
        public void setListDataHeader(List<String> list){
        this._listDataHeader = list;
        }
    
        public void setListDataChild(List<String> list){
        this._listDataChild = list;
        }
    
    public void setSearchResponse(SearchResponse response){
        this.response = response;
    
    }    
    
        @Override
        public Object getChild(int groupPosition, int childPosititon) {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .get(childPosititon);
        }
    
        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }
    
        @Override
        public View getChildView(final int groupPosition, final int childPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {
    
            childText = (String) getChild(groupPosition, childPosition);
            final ViewHolder holder;
            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.list_item, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
    
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
    
            holder.txtListChild.setText(childText); // Here whatever you will type in edittext will be overwritten by the value of 'childText.getTotal'. So after you are done writing in edit text make sore you change that in "_listDataChild" list.
    
    
            newlist = new ArrayList<String>();
            newlist1 = new ArrayList<String>();
            list1=new ArrayList<>();
            list1.add(childText);
            final TextView txtListChild1 = (TextView) convertView
                    .findViewById(R.id.flash1);
    
    
    
    
    
            txtListChild1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
    
                    if (onclick) {
    
                        txtListChild1.setText("Save");
                        holder.txtListChild.setEnabled(true);
                        onclick = false;
                    } else {
    
                        //  ArrayList<String> itemList=new ArrayList<String>();
                        //itemList.add();
                        onclick = true;
                        txtListChild1.setText("Edit");
                        holder.txtListChild.setEnabled(false);
                        newlist.add(response.getModule()[groupPosition].getSwitches()[childPosition].getSwitchId().getId());
                        newlist1.add(holder.txtListChild.getText().toString());
                        String url = "http://dashboard.droidhomes.in/api/switch";
                        RequestQueue requestQueue = Volley.newRequestQueue(_context);
                        JSONObject dataObj = new JSONObject();
                        try {
    
                            JSONArray cartItemsArray = new JSONArray();
                            JSONObject cartItemsObjedct;
                            for(int i=0;i<newlist.size();i++){
    
                                cartItemsObjedct = new JSONObject();
                                cartItemsObjedct.putOpt("switch_id", newlist.get(i));
                                cartItemsObjedct.putOpt("switch_name",newlist1.get(i));
                                cartItemsArray.put(cartItemsObjedct);
    
    
                            }
    
                            dataObj.put("update_list", cartItemsArray);
    
    
                            JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(Request.Method.PUT, url, dataObj, new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject response) {
                                    try {
                                        Toast.makeText(_context, response.getString("status"), Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                    //mTextView.setText(error.toString());
                                }
                            }) {
                                @Override
                                public Map<String, String> getHeaders() throws AuthFailureError {
                                    Map<String, String> headers = new HashMap<>();
                                    headers.put("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ijk5MjEyMzQ4MTMiLCJyb2xlIjoiY3VzdG9tZXIiLCJpZCI6IjU4M2VhZjI0OWM1ZDM5MTgyMzk0MTkzNyIsIm5hbWUiOiJWaWpheSBNYWxob3RyYSJ9.aF-vgNvOSSk_mbi_cTGufG2JZRrmP38zPFGn9UK9iMA");
                                    headers.put("Content-Type", "application/json");
                                    return headers;
                                }
                            };
                            requestQueue.add(jsonArrayRequest);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
    
    
                    }
    
    
                }
            });
    
    
            return convertView;
    
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .size();
        }
    
        @Override
        public Object getGroup(int groupPosition) {
            return this._listDataHeader.get(groupPosition);
        }
    
        @Override
        public int getGroupCount() {
            return this._listDataHeader.size();
        }
    
        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }
    
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                                 View convertView, ViewGroup parent) {
            String headerTitle = (String) getGroup(groupPosition);
            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.list_group, null);
            }
    
            TextView lblListHeader = (TextView) convertView
                    .findViewById(R.id.lblListHeader);
            lblListHeader.setTypeface(null, Typeface.BOLD);
            lblListHeader.setText(headerTitle);
    
            return convertView;
        }
    
        @Override
        public boolean hasStableIds() {
            return false;
        }
    
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    
        class ViewHolder {
            EditText txtListChild;
    
            public ViewHolder(View v) {
                txtListChild = (EditText) v.findViewById(R.id.lblListItem);
            }
        }
    
        public HashMap<String,List<String>> gethashmap() {
    
            return _listDataChild;
        }
    

    【讨论】:

    • 您好@Android 开发人员:您的代码中有错误:- 我得到 java.lang.NullPointerException:尝试调用虚拟方法 'droidhomes.droidhomes.activities.Modules[] droidhomes.droidhomes.activities .SearchResponse.getModule()' 在 droidhomes.droidhomes.activities.ExpandableListAdapter1$1.onClick(ExpandableListAdapter1.java:122) 处的空对象引用上
    • 让我检查一下,它会修复的。
    • ExpandableList‌​Adapter1.java 中的第 122 行是什么?看来我的代码中的行号和你放在项目中的代码是不同的。
    • :同样的问题再次恢复相同的值。
    猜你喜欢
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多