編集テキストをクリックすると.....logcatのようにエラーが発生します
DatePickerDate.java
public class DatePickerDate extends FragmentActivity {
EditText mEdit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_page);
}
public void selectDate(View view) {
DialogFragment newFragment = new SelectDateFragment();
newFragment.show(getSupportFragmentManager(), "DatePicker");
}
public void populateSetDate(int year, int month, int day) {
mEdit = (EditText)findViewById(R.id.DATE_EDIT_TEXT_ID);
mEdit.setText(month+"/"+day+"/"+year);
}
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
}
}
}
search_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectDate"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="date" />
<EditText
android:id="@+id/DATE_EDIT_TEXT_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:onClick="selectDate"
android:inputType="date" >
<requestFocus />
</EditText>
</LinearLayout>
ログキャット
10-04 23:11:42.655: E/AndroidRuntime(2000): FATAL EXCEPTION: main
10-04 23:11:42.655: E/AndroidRuntime(2000): java.lang.IllegalStateException: Could not find a method selectDate(View) in the activity class com.project.findmybuffet.SearchPage for onClick handler on view class android.widget.EditText with id 'DATE_EDIT_TEXT_ID'
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.view.View$1.onClick(View.java:2131)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.view.View.performClick(View.java:2485)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.view.View$PerformClick.run(View.java:9080)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.os.Handler.handleCallback(Handler.java:587)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.os.Looper.loop(Looper.java:123)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 23:11:42.655: E/AndroidRuntime(2000): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 23:11:42.655: E/AndroidRuntime(2000): at java.lang.reflect.Method.invoke(Method.java:507)
10-04 23:11:42.655: E/AndroidRuntime(2000): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 23:11:42.655: E/AndroidRuntime(2000): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 23:11:42.655: E/AndroidRuntime(2000): at dalvik.system.NativeStart.main(Native Method)
10-04 23:11:42.655: E/AndroidRuntime(2000): Caused by: java.lang.NoSuchMethodException: selectDate
10-04 23:11:42.655: E/AndroidRuntime(2000): at java.lang.ClassCache.findMethodByName(ClassCache.java:247)
10-04 23:11:42.655: E/AndroidRuntime(2000): at java.lang.Class.getMethod(Class.java:962)
10-04 23:11:42.655: E/AndroidRuntime(2000): at android.view.View$1.onClick(View.java:2124)
これを解決する方法!
[アップデート]
SearchPage.java
public class SearchPage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.search_page);
}
}