gpt4 book ai didi

java - android.support.design.widget.TabItem 无法转换为 android.view.ViewGroup

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

我在运行时遇到以下错误。

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.usamaakmal.trackpoint, PID: 8774 android.view.InflateException: Binary XML file line #0: android.support.design.widget.TabItem cannot be cast to android.view.ViewGroup Caused by: java.lang.ClassCastException: android.support.design.widget.TabItem cannot be cast to android.view.ViewGroup at android.view.LayoutInflater.rInflate(LayoutInflater.java:870) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832) at android.view.LayoutInflater.rInflate(LayoutInflater.java:872) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832) at android.view.LayoutInflater.rInflate(LayoutInflater.java:872) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at com.example.usamaakmal.trackpoint.PresentationLayer.Dialogs.DateTimePickerDialog.onCreateView(DateTimePickerDialog.java:20) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700) at android.os.Handler.handleCallback(Handler.java:761) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6523) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

我的 XML 布局如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Select Date And Time"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:id="@+id/tv_date_time_title"/>


<android.support.design.widget.TabLayout
android:id="@+id/date_time_tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tv_date_time_title"
android:layout_centerVertical="true">

<android.support.design.widget.TabItem
android:id="@+id/tab_date_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date">

<DatePicker android:id="@+id/dp_date_picker"></DatePicker>

</android.support.design.widget.TabItem>

<android.support.design.widget.TabItem
android:id="@+id/tab_time_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time">

<TimePicker android:id="@+id/tp_time_picker"></TimePicker>
</android.support.design.widget.TabItem>
</android.support.design.widget.TabLayout>
</RelativeLayout>

我的自定义对话框 fragment 类在下面

public class DateTimePickerDialog extends DialogFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.date_time_picker_layout,container,false);
return view;
}
}

最佳答案

TabItem 扩展ViewReference here .因此,您不能在 TabItem 中包含另一个 View 。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Select Date And Time"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:id="@+id/tv_date_time_title"/>


<android.support.design.widget.TabLayout
android:id="@+id/date_time_tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tv_date_time_title"
android:layout_centerVertical="true">

<android.support.design.widget.TabItem
android:id="@+id/tab_date_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date" />

<android.support.design.widget.TabItem
android:id="@+id/tab_time_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time" />
</android.support.design.widget.TabLayout>
</RelativeLayout>

关于java - android.support.design.widget.TabItem 无法转换为 android.view.ViewGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49486467/

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