Android에서 간단한 TimePickerDialog를 구현하려고하는데 오류가 발생합니다. 나는이 구글에서 튜토리얼 다음 오전 : 내 코드에서 https://developer.android.com/guide/topics/ui/controls/pickers.htmlAndroid의 TimePickerDialog
을, 나는 그러나, TimePicker의 전망을 감상 할 수있는 DialogFragment를 표시한다 클릭하면, 내가 컴파일 오류가 있는지 setFromTimeButton라는 버튼이 있습니다
Cannot resolve symbol TimePickerFragment()
을 이유를 아시겠습니까? 고맙습니다!
이
내 클래스 :package it.bitrack.fabio.bitrack;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
//import android.app.Fragment;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import android.app.Dialog;
import android.text.format.DateFormat;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog;
import android.icu.util.Calendar;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Button;
import android.widget.TextView;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link ScheduleView.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link ScheduleView#newInstance} factory method to
* create an instance of this fragment.
*/
public class ScheduleView extends DialogFragment implements TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
Button setFromTimeButton;
android.support.v4.app.FragmentManager fragmentManager;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public ScheduleView() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ScheduleView.
*/
// TODO: Rename and change types and number of parameters
public static ScheduleView newInstance(String param1, String param2) {
ScheduleView fragment = new ScheduleView();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_schedule_view, container, false);
setFromTimeButton = (Button) view.findViewById(R.id.setFromTimeButton);
fragmentManager = getFragmentManager();
setFromTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(fragmentManager, "timePicker");
}
});
return view;
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
}
다음과 같은 클래스를 추가 할 필요가
질문의 코드에 'TimePickerFragment'가 없습니다. 하나를 만드는 방법은 [연결된 문서] (https://developer.android.com/guide/topics/ui/controls/pickers.html)에서 다룹니다. – CommonsWare
@CommonsWare 그래서 TimePickerFragment라는 다른 클래스를 생성해야합니까? –
예 - rafsanahmad007의 답변을 참조하십시오. – CommonsWare