gpt4 book ai didi

android - 无法解析方法 'show(android.support.v4.app.FragmentManager,java.lang.String)'

转载 作者:太空狗 更新时间:2023-10-29 16:29:58 25 4
gpt4 key购买 nike

在 TimePickerDailog 中给我错误,如 Cannot resolve method'show(android.support.v4.app.FragmentManager, java.lang.String)'

我从我试过的另一个网站获得了这个教程,但没有得到输出并得到同样的错误。 我在 stackoverflow 中提到了相同的问题,但没有得到结果,所以我发布了这个问题。

在这一行给我错误:-

    dFragment.show(getFragmentManager(),"Time Picker");

这里是代码:-

  public class Daily_Task extends Fragment {
public Daily_Task() {};
Button submittask;
View view;

EditText starttime, endtime;
EditText Taskname, Detail;
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_daily__task, container, false);
getActivity().setTitle("Task");
starttime = (EditText) view.findViewById(R.id.start_time);
endtime = (EditText) view.findViewById(R.id.End_time);
submittask = (Button) view.findViewById(R.id.add_task_button);

starttime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Initialize a new time picker dialog fragment
DialogFragment dFragment = new TimePickerFragment();

// Show the time picker dialog fragment
dFragment.show(getFragmentManager(),"Time Picker");

}
});

return view;
}

TimePickerFragment.java

  package com.Weal.sachin.omcom;

/**
* Created by sachin on 2/1/2017.
*/

import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.widget.TextView;
import android.app.DialogFragment;
import android.app.Dialog;
import java.util.Calendar;
import android.widget.TimePicker;

public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
// Get a Calendar instance
final Calendar calendar = Calendar.getInstance();
// Get the current hour and minute
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);

/*
Creates a new time picker dialog with the specified theme.

TimePickerDialog(Context context, int themeResId,
TimePickerDialog.OnTimeSetListener listener,
int hourOfDay, int minute, boolean is24HourView)
*/

// TimePickerDialog Theme : THEME_DEVICE_DEFAULT_LIGHT
TimePickerDialog tpd = new TimePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,hour,minute,false);

// TimePickerDialog Theme : THEME_DEVICE_DEFAULT_DARK
TimePickerDialog tpd2 = new TimePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_DARK,this,hour,minute,false);

// TimePickerDialog Theme : THEME_HOLO_DARK
TimePickerDialog tpd3 = new TimePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_DARK,this,hour,minute,false);

// TimePickerDialog Theme : THEME_HOLO_LIGHT
TimePickerDialog tpd4 = new TimePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,hour,minute,false);

// TimePickerDialog Theme : THEME_TRADITIONAL
TimePickerDialog tpd5 = new TimePickerDialog(getActivity(),
AlertDialog.THEME_TRADITIONAL,this,hour,minute,false);

// Return the TimePickerDialog
return tpd;
}

public void onTimeSet(TimePicker view, int hourOfDay, int minute){
// Do something with the returned time
TextView tv = (TextView) getActivity().findViewById(R.id.start_time);
tv.setText("HH:MM\n" + hourOfDay + ":" + minute);
}
}

最佳答案

这样试试

对于 android.support.v4.app.DialogFragment

dFragment.show(getActivity().getSupportFragmentManager(),"Time Picker");

对于 android.app.DialogFragment

dFragment.show(getActivity().getFragmentManager(),"Time Picker");

并且持有这个 fragment 的 Activity 应该扩展 AppCombatActivity

关于android - 无法解析方法 'show(android.support.v4.app.FragmentManager,java.lang.String)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41981546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com