メニューのオプションをクリックしてカスタムダイアログボックスを作成しようとしています。 IntentがcustomTextMessageDialogを指している新しいアクティビティを開始するように進みます。Android - カスタムダイアログでコンポーネントのハンドルを取得する
I 午前のようなコードを使用して、私のcustomdialog.xmlファイルで定義されたウィジェットのいずれかにハンドルを得ることができる「にphoneNumber =(のEditText)dialog.findViewById(R.id.customDialogPhoneNumber1を);」
しかし、私ははこのハンドルで何もできません。私はEditTextハンドルのsetText()しようとするか、私のアプリケーションでクラッシュする私のxmlで定義されたボタンのいずれかのonClickListenerを設定する場合。なぜこれが起こっているか、どのように私はこれを修正することができますか?
また、そのインスタンスでfindViewByIdを呼び出す前にDialogのインスタンスを最初に作成する必要があるのはなぜですか?あなたのコードで
public class customTextMessageDialog extends Activity
{
EditText phoneNumber;
EditText message;
Button cancelButton;
Button sendButton;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.customdialog);
Dialog dialog = new Dialog(this);
phoneNumber = (EditText)dialog.findViewById(R.id.customDialogPhoneNumber1);
//phoneNumber.setTextColor(R.color.gray);
//phoneNumber.setText("ex: 4127214544");
message = (EditText)dialog.findViewById(R.id.customDialogMessage1);
cancelButton = (Button)dialog.findViewById(R.id.customDialogCancelButton1);
cancelButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
finish();
}
});
sendButton = (Button)dialog.findViewById(R.id.customDialogPhoneNumber1);
}
}
こんにちは、それを指摘してくれてありがとう。私はその変更を行った。しかし、私が持っているさまざまな要素へのハンドルを変更しようとすると、私のコードはまだクラッシュします。 – roro