0

提前致谢。

我正在使用 sherlockActionbar 并且在主要活动布局中我使用 FrameLayout 如下

Mainactivity 布局文件将如下所示

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
 >

<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/content_frame"
    />
<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
android:layout_alignParentBottom="true" style="@android:style/ButtonBar" 
android:background="#111">

<Button android:id="@+id/menu" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="Menu"
    android:background="#111"/>
 <Button android:id="@+id/offers" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="Offers" 
  android:background="#111" />
  <Button android:id="@+id/home" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="Home"
    android:background="#111"/>

<Button android:id="@+id/cart" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="Cart" 
    android:background="#111"/>

在主要活动中,我只是替换片段如下

public class MainActivity extends SherlockActivity {
  SlidingMenu menu ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from activity_main.xml

    setContentView(R.layout.activity_main);

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.main_menu, null);
    String[] items = new String[]{"Menu","Offers","Cart","Todays Special"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this ,android.R.layout.simple_list_item_1, android.R.id.text1, items);
    ListView lv = (ListView) view.findViewById(R.id.list);
    lv.setAdapter(adapter);



    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setMenu(view);
   menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

    menu.setBehindOffset(120);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
   AreaSelection AreaFragment=new AreaSelection();

    final android.app.FragmentTransaction ft =   getFragmentManager().beginTransaction(); 
    ft.replace(R.id.content_frame,AreaFragment ,"Area"); 
    ft.commit();


}

由于所有代码都适用于版本高于 3.0 的 android 设备,但在低于 3.0 的版本中无法正常工作,因此出现 Class Deff Not Found 错误

区域选择片段将如下所示

public class AreaSelection extends Fragment{


MainDatabase db;

     public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
      {

        View localView = paramLayoutInflater.inflate(R.layout.area_select, paramViewGroup, false);
        db=new MainDatabase(getActivity());
        Button proceed=(Button)localView.findViewById(R.id.proceed);

        proceed.setOnClickListener(this.ProccedListener);
        String[] area = new String[]{"Sangvi","Aundh","University","Shivaji Nagar","E-Square Area"};
        ArrayAdapter<String> spinner_adapter = new ArrayAdapter<String>(getActivity() ,android.R.layout.simple_list_item_1, android.R.id.text1, area);

        Spinner s=(Spinner)localView.findViewById(R.id.spinner);

        s.setAdapter(spinner_adapter);

        return localView;


      }
  }

Logcat如下

10-06 11:39:00.988: E/AndroidRuntime(280): FATAL EXCEPTION: main
10-06 11:39:00.988: E/AndroidRuntime(280): java.lang.NoClassDefFoundError:    com.community.ashwamedh.AreaSelection
10-06 11:39:00.988: E/AndroidRuntime(280):  at com.community.ashwamedh.MainActivity.onCreate(MainActivity.java:55)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.os.Looper.loop(Looper.java:123)
10-06 11:39:00.988: E/AndroidRuntime(280):  at android.app.ActivityThread.main(ActivityThread.java:4627)
10-06 11:39:00.988: E/AndroidRuntime(280):  at java.lang.reflect.Method.invokeNative(Native Method)
10-06 11:39:00.988: E/AndroidRuntime(280):  at java.lang.reflect.Method.invoke(Method.java:521)
10-06 11:39:00.988: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 10-06 11:39:00.988: E/AndroidRuntime(280):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 10-06 11:39:00.988: E/AndroidRuntime(280):     at dalvik.system.NativeStart.main(Native Method)

请帮我

再次感谢

4

1 回答 1

0

Fragment 类首先在 Homecomb(Android 3.0)中引入。如果您想在旧版本的 Android 中使用此功能,您应该从支持库中导入它。确保您使用的是android.support.v4.app导入,而不是来自android.app.

于 2013-10-06T06:27:36.673 回答