I commented on some parts of your code that seemed a bit unnecessary. However, I'm not sure about the code associated with the Comment class. In this context, at least, it seemed redundant.
previousCommentsList = (ListView) findViewById(R.id.previous_comments_list); commentsArrayList = new ArrayList<String>(); for (Comment comment : DrawView.comments) { commentsArrayList.add(comment.text); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, commentsArrayList); previousCommentsList.setAdapter(adapter); saveCommentButton = (Button) findViewById(R.id.save_comment_button); saveCommentButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { EditText commentEditText = (EditText) findViewById(R.id.comment_edittext); // COMMENT: Is creating a comment object really neccessary, if it only serves the purpose of saving a text ? Comment comment = new Comment(); comment.text = commentEditText.getText().toString(); // DrawView.comments.add(comment); COMMENT: -> Is this neccessary? Toast.makeText(getApplicationContext(), "Comment saved", Toast.LENGTH_SHORT).show(); // commentsArrayList = new ArrayList<String>(); // for (Comment comment2 : DrawView.comments) { commentsArrayList.add(comment.text); // } // ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, commentsArrayList); // previousCommentsList.setAdapter(adapter); adapter.notifyDataSetChanged(); } });
source share