Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.85 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Settext of EditText from another class gives nullpointer
  2. public class RoundCommentDialog extends Dialog implements View.OnClickListener {
  3.  
  4.     private Context context;
  5.  
  6.     private String roundCommentText;    
  7.     private EditText roundCommentEditText;
  8.  
  9.     private Button postiveButton;
  10.     private Button negativeButton;
  11.  
  12.     public RoundCommentDialog(Context context) {
  13.         super(context);
  14.     }
  15.  
  16.     public void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.custom_round_comment_dialog);
  19.  
  20.         postiveButton = (Button) findViewById(R.id.dialog_positive_button);
  21.         postiveButton.setOnClickListener (this);
  22.         negativeButton = (Button) findViewById(R.id.dialog_negative_button);
  23.         negativeButton.setOnClickListener (this);
  24.  
  25.         roundCommentEditText = (EditText) findViewById(R.id.comment_text);
  26.  
  27.     }
  28.  
  29.     public void setRoundCommentText(String roundCommentText) {
  30.         this.roundCommentText = roundCommentText;
  31.     }
  32.  
  33.     public String getRoundCommentText() {
  34.         return roundCommentEditText.getText().toString();
  35.     }
  36.  
  37.     public void updateCommentEditField() {
  38.  
  39.         roundCommentEditText.setText("TEST");
  40.     }
  41.  
  42.     public Dialog getDialog() {
  43.         updateCommentEditField();
  44.         return this;
  45.     }
  46.  
  47.     public void onClick(View v) {
  48.         switch (v.getId()) {
  49.         case R.id.dialog_positive_button:
  50.  
  51.             setRoundCommentText(roundCommentText);
  52.  
  53.             dismiss();
  54.             break;
  55.         case R.id.dialog_negative_button:
  56.             cancel();
  57.             break;
  58.         }
  59.  
  60.     }
  61.  
  62.  
  63. }
  64.        
  65. RoundCommentDialog myDialog = new RoundCommentDialog(this);
  66.        
  67. myDialog.setRoundCommentText(roundComentText);
  68. myDialog.getDialog().show();
  69.        
  70. roundCommentEditText.setText("TEST");
  71.        
  72. private String roundCommentText;
  73.        
  74. public String roundCommentText;