我每次点击DatePicker Fragment
时都会尝试显示Button
。但我得到了“不兼容的类型”:
public class InserirActivity extends BaseActivity implements BaseActivity.OnInfoChangedListener{
(...)
public void clicando (View v){
DialogFragment newFragment;
newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
问题发生在newFragment = new DatePickerFragment();
,因为我收到错误"Incompatible Types"
。
由于与另一个Fragment的回调,此活动扩展到BaseActivity。
这是我的DatePickerFragment
:
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
Log.d("DatePicker","Here!");
}
}
我称之为layout.xml
的程序clicando()
:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_marginRight="5dp"
android:id="@+id/buttonOk"
android:onClick="clickando"
android:background="@drawable/buttons_1"
android:textColor="@color/green7"/>
我已经在这里阅读了很多类似的问题/解决方案,但我找不到一个。你能帮我么?
答案 0 :(得分:1)
在检查了我注意到的所有内容之后
import android.support.v4.app.DialogFragment;
而不是
import android.app.DialogFragment;