I have a problem to how can I display a different xml layout for a modified list view.
My list view acts as a comment section.
I just want to display a edit and delete button for the owner of that certain comment and display nothing at all if he/she is not the owner of it.
this is my sample code btw I am using json
protected void onPostExecute(JSONObject json) { HashMap<String, String> user = session.sessionGetIdAccountType(); String session_user_id = user.get(UserSessionManager.KEY_ID); int integer_session_user_id = Integer.parseInt(session_user_id); String user_id = ""; boolean usercomment = false; try { commentData = json.getJSONArray("list"); for (int i = 0; i < commentData.length(); i++) { JSONObject source = commentData.getJSONObject(i); Commenters commenter = new Commenters(); commenter.setName(source.getString("User_Fname") + " " + source.getString("User_Lname")); commenter.setDate(source.getString("Comment_Date")); commenter.setUsername(source.getString("User_Username")); commenter.setComment(source.getString("Comment_Content")); int integer_user_id = Integer.parseInt(user_id = source .getString("User_ID")); commenterList.add(commenter); ListView listview = (ListView) findViewById(R.id.comment_list); if (integer_session_user_id == integer_user_id) { usercomment = true; } else { usercomment = false; } if (usercomment) { adapter2 = new CommenterAdapter2( getApplicationContext(), R.layout.row_user, commenterList); listview.setAdapter(adapter2); } else { adapter = new CommenterAdapter(getApplicationContext(), R.layout.row, commenterList); listview.setAdapter(adapter); } } } catch (Exception e) { e.fillInStackTrace(); } }
No comments:
Post a Comment