カスタムアダプタを使用してlistviewに連絡先を表示しています。アイテムをクリックするとカスタムダイアログを開くonClick関数を作成します。その後、私はダイアログボックスから連絡先番号を取得したいが、エラーポップアップを取得しようとするとき。Androidのカスタムダイアログから値を取得
IllegalStateException: Could not execute method for android:onClick
カスタムダイアログカスタムからアダプタ
// Other code
// This code is working fine problem is in activity class
public void onClick(View v) {
Toast.makeText(context, "Item click", Toast.LENGTH_SHORT).show();
String phoneNumber = phone.getText().toString();
String userName = name.getText().toString();
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(userName);
EditText etxtContactNumber = (EditText) dialog.findViewById(R.id.etxtContactNumber);
etxtContactNumber.setText(phoneNumber);
dialog.show();
}
// reset of the code
カスタムダイアログ
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/etxtContactNumber" />
<Button
android:text="Send SMS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnSendMessage"
android:onClick="sendMessage" />
<Button
android:text="Phone Call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnPhoneCall"
android:onClick="phoneCall" />
主な活動
protected void sendMessage(View view){
Toast.makeText(this, "Send Message", Toast.LENGTH_SHORT).show();
EditText etxtContactNumber = (EditText) view.findViewById(R.id.etxtContactNumber);
String phoneNumber = etxtContactNumber.getText().toString();
String uri= "smsto:"+phoneNumber;
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
startActivity(intent);
}
私はエラーの理由を知っていますetxtContactNumber
はこのビューにありません。これは主なアクティビティビューではなく、どのように取得できるのですか。
カスタムアダプタとMainActivity両方2つの異なるファイルです
「パブlic void sendMessage' –
'public'が動作していません –