- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用对话框 fragment 来选择日期,但无法解析下面 Signigicant_Other 类中的 timePickerFragment.show(...) 方法。智能感知也建议使用 show 方法。我不清楚为什么它没有解决,恐怕我只是没有看到一些简单的事情。仅供引用,我遵循了这些教程:
http://developer.android.com/guide/topics/ui/controls/pickers.html http://www.androidbegin.com/tutorial/android-dialogfragment-tutorial/
调用 fragment 的 Activity :
package com.mycompany.dudesmyreminders;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class Significant_Other extends ActionBarActivity {
Button birthbutton;
Button annibutton;
FragmentManager fm = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_significant__other);
// Locate the button in activity_main.xml
birthbutton = (Button) findViewById(R.id.SignificanOther_birthButton);
annibutton = (Button) findViewById(R.id.SignificanOther_annivButton);
// Capture button clicks
birthbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
TimePickerFragment timePickerFragment = new TimePickerFragment();
// Show DialogFragment
timePickerFragment.show(fm, "Time Picker"); //THE PROBLEM IS HERE
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_significant__other, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
编辑:解决方案是如下所示的更改
将具有日期选择器的 fragment :
package com.mycompany.dudesmyreminders;
import android.app.Activity;
import android.app.Dialog;
//Solution was to change android.app.DialogFragment; to android.support.v4.app.DialogFragment;
//import android.app.DialogFragment;
import android.support.v4.app.DialogFragment;
import android.app.TimePickerDialog;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TimePicker;
import java.util.Calendar;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link TimePickerFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
*/
public class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener{
private OnFragmentInteractionListener mListener;
public TimePickerFragment() {
// Required empty public constructor
}
@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()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* 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
public void onFragmentInteraction(Uri uri);
}
}
最佳答案
你需要使用
import android.support.v4.app.DialogFragment;
因为您正在使用 SupportFragmentManager。祝你好运!
关于android - TimepickerFragment show() 方法无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29054055/
我有一个可用的 TimePickerFragment,它使用当前时间作为选择器的默认值。现在我想传递分钟和小时的旧选定值以显示在选择器中。我该怎么做? 这是代码: Activity : Tim
我会使用 TimePickerFragment 来设置时间,它可以完美地工作。 我只想在用户点击“取消”按钮时执行一个操作。 不幸的是,到目前为止我还没有找到如何去做。 这是我的代码: 创建对话框:
根据官方Android Devguide ,当用户点击该按钮时,系统调用如下方法: public void showTimePickerDialog(View v) { DialogFragm
我正在尝试使用对话框 fragment 来选择日期,但无法解析下面 Signigicant_Other 类中的 timePickerFragment.show(...) 方法。智能感知也建议使用 sh
我开始在 Android 中尝试时间和日期选择器。 我的类(class)如下: Main.java package com.valgriz.testapplication2; import andr
我是一名优秀的程序员,十分优秀!