日期选择器正在SherlockFragmentActivity上关闭

时间:2013-03-19 07:48:29

标签: android android-fragments actionbarsherlock android-fragmentactivity android-datepicker

这是我的代码,它没有显示任何错误。当我试图让它关闭时,ClassCastException

注意:在延伸到SherlockFragment时,相同的代码正在工作

public class EventsFeatured extends SherlockFragmentActivity {
TextView cal;
View view;

int year;
int month;
int day;


public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.events_featured, container, false);
    iniitialize();

    return view;
}

private void iniitialize() {
    // TODO Auto-generated method stub
    Calendar t = Calendar.getInstance();
    year = t.get(Calendar.YEAR);
    month = t.get(Calendar.MONTH);
    day = t.get(Calendar.DAY_OF_MONTH);
    cal = (TextView) view.findViewById(R.id.tvCalendar);
    cal.setText(new StringBuilder()
    .append(month + 1).append("-").append(day).append("-")
    .append(year).append(" "));
}
    }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码失败了,因为在TabsAdapter的{​​{1}}方法中,您尝试从不属于{的类创建getItem()Fragment) {1}}(正如SherlockFragment方法所期望的那样),该类是Fragment

为什么getItem()需要SherlockFragmentActivity来扩展EventsFeatured,从它的外观(以及如何使用它)开始,该类应该扩展SherlockFragmentActivity?例如,SherlockFragment中有onCreateView()方法,它只是一个简单的方法,它不是创建EventsFeatured视图的片段的回调方法。

如果你需要活动作为标签,你需要使用Fragment(但是,你不应该使用它,因为它已被弃用)。