Android 碎片使用中的问题
嗨,我有一个xml布局,我在每个布局中都将其作为一个片段包含 这是我在maincegories.xml中的xmlAndroid 碎片使用中的问题,android,android-fragments,android-fragmentactivity,Android,Android Fragments,Android Fragmentactivity,嗨,我有一个xml布局,我在每个布局中都将其作为一个片段包含 这是我在maincegories.xml中的xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_h
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/mainbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/logo"
android:src="@drawable/logo" />
</LinearLayout>
<View
android:id="@+id/viewLine"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/txtUserName"
android:background="#cccccc" />
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:fastScrollEnabled="true"
android:listSelector="@drawable/list_selector"
android:smoothScrollbar="true" />
<fragment
android:name="com.rag.xmlparsing.fragmentactivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
而碎片活动类是
public class fragmentactivity extends FragmentActivity {
RadioButton radioButton;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.actnavbar,
container, false);
radioButton = (RadioButton) view.findViewById(R.id.home);
radioButton.setOnCheckedChangeListener(btnNavBarOnCheckedChangeListener);
radioButton = (RadioButton) view.findViewById(R.id.aboutus);
radioButton.setOnCheckedChangeListener(btnNavBarOnCheckedChangeListener);
radioButton = (RadioButton) view.findViewById(R.id.contactus);
radioButton.setOnCheckedChangeListener(btnNavBarOnCheckedChangeListener);
radioButton = (RadioButton) view.findViewById(R.id.orderhistory);
radioButton.setOnCheckedChangeListener(btnNavBarOnCheckedChangeListener);
return view;
}
private CompoundButton.OnCheckedChangeListener btnNavBarOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int sid=buttonView.getId();
int hme=R.id.home;
int abtus=R.id.aboutus;
int cnt=R.id.contactus;
int ordr=R.id.orderhistory;
if (isChecked) {
if(sid==hme)
{
//some function
}
else if(sid==abtus)
{
//some function
}
else if(sid==cnt)
{
//
}
else if(sid==ordr)
{
}
}
}
};
}
还有我的actnavbar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="@android:color/white"
>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:padding="5dp"
android:background="#cccccc"
>
<RadioButton
android:id="@+id/home"
style="@style/navbar_button"
android:drawableTop="@drawable/home_icon"
android:text="Home"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:textSize="12sp"
android:textColor="#333333"
/>
<RadioButton
android:id="@+id/aboutus"
style="@style/navbar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About us"
android:textSize="12sp"
android:textColor="#333333"
android:drawableTop="@drawable/aboutus_icon"
android:gravity="center_horizontal" />
<RadioButton
android:id="@+id/contactus"
style="@style/navbar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="Contact us"
android:textColor="#333333"
android:drawableTop="@drawable/contact_icon"
android:gravity="center_horizontal" />
<RadioButton
android:id="@+id/orderhistory"
style="@style/navbar_button"
android:drawableTop="@drawable/order_history_icon"
android:text="Order history"
android:textSize="12sp"
android:textColor="#333333"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
/>
</RadioGroup>
</RelativeLayout>
我在哪里犯了错误???请给出任何建议。首先,您的类
**fragmentactivity**
是fragmentactivity,您不能在xml文件中使用它
你的代码
public class fragmentactivity extends FragmentActivity
查看类代码
public class fragmentactivity extends Fragment
只有视图类
文件才能在xml
文件中使用
这就是您面临java.lang.ClassNotFoundException:android.view.fragment
错误的原因
这里有很多关于片段的例子
public class fragmentactivity extends FragmentActivity
public class fragmentactivity extends Fragment