0

I am trying to create facebook like sliding i have tried this library seems its not working for me..I need something like this screen.. where in the sliding layout the listview with header and while click on that in the same activity content should change.actually using the above library i tried like this:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.attach);
        // set the content view
        setContentView(R.layout.content);
        // configure the SlidingMenu
        SlidingMenu menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setShadowWidthRes(R.dimen.shadow_width);
        menu.setShadowDrawable(R.drawable.shadow);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.35f);
        menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        menu.setMenu(R.layout.menu);
    }

}

which is not at all working! error:

07-20 10:17:19.776: E/AndroidRuntime(1134): FATAL EXCEPTION: main
07-20 10:17:19.776: E/AndroidRuntime(1134): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.example/com.app.example.MainActivity}: java.lang.IllegalStateException: Both setBehindContentView must be called in onCreate in addition to setContentView.
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.os.Looper.loop(Looper.java:137)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invokeNative(Native Method)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invoke(Method.java:511)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at dalvik.system.NativeStart.main(Native Method)
07-20 10:17:19.776: E/AndroidRuntime(1134): Caused by: java.lang.IllegalStateException: Both setBehindContentView must be called in onCreate in addition to setContentView.
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityHelper.onPostCreate(SlidingActivityHelper.java:55)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity.onPostCreate(SlidingActivity.java:36)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1143)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
07-20 10:17:19.776: E/AndroidRuntime(1134):     ... 11 more

menu xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.app.example.SampleListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</fragment>

manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.example"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         android:theme="@style/Theme.Myactionbar" 
        >
        <activity
            android:name="com.app.example.MainActivity"
            android:configChanges="orientation|screenSize|screenLayout"
           >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>



</manifest>

enter image description here

Could somebody help me out @thanks

4 Answers4

1

go through this http://developer.android.com/design/patterns/navigation-drawer.html no need for extra 3rd party libs

Onur A.
  • 3,007
  • 3
  • 22
  • 37
0

go through this:: https://github.com/jfeinstein10/SlidingMenu

This will sure helpful to you.

Karan Maru
  • 991
  • 6
  • 17
0

Inside your AndroidManifest.xml you have declared com.app.example.MainActivity but your Activity is named com.app.example.SlidingExample

Change

<activity
        android:name="com.app.example.MainActivity"
        android:configChanges="orientation|screenSize|screenLayout"
       >

with

<activity
        android:name="com.app.example.SlidingExample"
        android:configChanges="orientation|screenSize|screenLayout"
       >
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

the layout containing the listview that you want dispay in the sliding menu should be set using setBehindContentView(R.layout.yourlistlayout);you could do that after setcontentview() in your code.

you can add header to your listview like this

 TextView header = new TextView(this);
header.setText("Effects");
header.setTextColor(Color.WHITE);
header.setPadding(10, 10, 10, 10);
header.setTextSize(20);
header.setBackgroundColor(Color.parseColor("#054472"));
lv.addHeaderView(header);

As an alternative you can use the new NavigationDrawer made available by google in the recent API.but again it is not available for older versions of android,which means you will have to use a library(like ActioBarSherlock) for backward compatibility. So its up to you. here is the link for navigation drawer. http://developer.android.com/training/implementing-navigation/nav-drawer.html

shreyas
  • 2,166
  • 3
  • 18
  • 30
  • Can we direct it from Right to Left – Sam-In-TechValens Jul 25 '13 at 10:26
  • I havent tried that... but if it is that important you can use Sliding Menu by jfeinstein10.it has been used by many good apps.you can have a sliding menu on both sides at the same time using this library... – shreyas Jul 25 '13 at 11:12