- Settext of EditText from another class gives nullpointer
- public class RoundCommentDialog extends Dialog implements View.OnClickListener {
- private Context context;
- private String roundCommentText;
- private EditText roundCommentEditText;
- private Button postiveButton;
- private Button negativeButton;
- public RoundCommentDialog(Context context) {
- super(context);
- }
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.custom_round_comment_dialog);
- postiveButton = (Button) findViewById(R.id.dialog_positive_button);
- postiveButton.setOnClickListener (this);
- negativeButton = (Button) findViewById(R.id.dialog_negative_button);
- negativeButton.setOnClickListener (this);
- roundCommentEditText = (EditText) findViewById(R.id.comment_text);
- }
- public void setRoundCommentText(String roundCommentText) {
- this.roundCommentText = roundCommentText;
- }
- public String getRoundCommentText() {
- return roundCommentEditText.getText().toString();
- }
- public void updateCommentEditField() {
- roundCommentEditText.setText("TEST");
- }
- public Dialog getDialog() {
- updateCommentEditField();
- return this;
- }
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.dialog_positive_button:
- setRoundCommentText(roundCommentText);
- dismiss();
- break;
- case R.id.dialog_negative_button:
- cancel();
- break;
- }
- }
- }
- RoundCommentDialog myDialog = new RoundCommentDialog(this);
- myDialog.setRoundCommentText(roundComentText);
- myDialog.getDialog().show();
- roundCommentEditText.setText("TEST");
- private String roundCommentText;
- public String roundCommentText;