我想在选择日期后在文本视图中设置日期,但它在我评论的行中抛出错误,如何修复它?
在这里创建视图
public class MoonFragment extends Fragment {
static {
System.loadLibrary("native-lib");
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_moon,
container, false);
final TextView moon_ra = (TextView) view.findViewById(R.id.moon_ra);
Button button = (Button) view.findViewById(R.id.moon_btn);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
moon_ra.setText(Double.toString(Aries(0.2)));
}
});
EditText moon_date = (EditText) view.findViewById(R.id.moon_date);
moon_date.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
DialogFragment newFragment = new SelectDateFragment(); // It throws error here
newFragment.show(getFragmentManager(), "DatePicker");
}
});
return view;
// return inflater.inflate(R.layout.activity_moon, container, false);
}
public native double Aries (double d);
在这里,我参加了选择日期的课程,它在第二行中抛出错误
public static class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
TextView moon_ra = (TextView)getActivity(). findViewById(R.id.moon_ra); // and here
@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);
}
也许还有其他方法可以在文本视图中设置日期?
慕森卡
慕丝7291255
相关分类