24

I am totally new to android, i am trying to implement Sliding Menu having ListView with Swipe Gesture, by some searching i found that https://github.com/jfeinstein10/SlidingMenu is exactly what i want,

There are many questions related to this which are guiding how integrate this library with project, but none of them are for new person like me. also procedure given on github is not detailed, all i know is how to add .jar file but this .zip and other things are totally new for me

This is what i have done till yet;

  1. downloaded zip from above link
  2. Extracted that link to folder
  3. in Eclipse File->import->existing project into work-space..

Now it is showing me many error in package library.src.com.slidingmenu.lib.app

e.g

The declared package "com.slidingmenu.lib.app" does not match the expected package "library.src.com.slidingmenu.lib.app"

now i don't know what to do...

please somebody guide me with proper detailed procedure of how to integrate and use this library in project.

Thanks !

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
john44
  • 243
  • 1
  • 2
  • 5

4 Answers4

40

Well, spending 3 days with same problem I found the exact procedure for this thing. The guide on github is of-course not for entry level guys like us, also there is no such a "step-by-step tutorial" for this, so it took time.

Important: I didn't include "Sherlock ActionBar" library, because I want to keep it simple

  • First up all update your eclipse to latest ADT or best way you can download this ADT Bundle, and confirm that everything is running fine in new ADTBundle.

  • Download latest "zip for jfeinstein10 / SlidingMenu" from "gitHub", And extract it anywhere you want. After extraction it must have these files and folders inside.

Folder after extracting library

  • Now open your eclipse File -> Import -> Android -> Existing Android Code Into Workspace, Browse to your folder most probably "SlidingMenu-master" and you should see following

enter image description here

Hit Finish, If eclipse shows some error like Unable to resolve target then change your target through Right Click on project -> Properties -> Android and check any latest google API your SDK have.

  • Add Dependency, by right clicking on project -> properties -> android -> library -> add -> SlidingMenuActivity, and clear both projects.

  • Add new XML layout named as menu_frame in your res -> layout and put following in it Put Frame Layout and list view in it.

  • Also add a ListView in your mainActivity XML file.

  • Now it is time to create "Menu" write following code in your onCreate() after setContentView(R.layout.activity_main).

    SlidingMenu menu;
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidth(5);
    menu.setFadeDegree(0.0f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setBehindWidth(200);
    menu.setMenu(R.layout.menu_frame);
    
  • At the lines it is showing error press ctrl+1 and import com.slidingmenu.lib.SlidingMenu;"

  • Run your project and you should see menu coming out from left side

  • Now the next task is to add adapter and listener for both of your ListViews (i.e for Main-screen and Menu).

For information about function used while creating Menu you can refer to example apps provided with library or google them, there is lot of info available.

Also thanks to "Jeremy Feinstein" for such a great library

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Saurabh Bayani
  • 3,350
  • 2
  • 25
  • 44
  • Hi , tanks for tutorial , how can i add item and Listner for ListViiew(Menu) is it possible in main activity ? – mahdi Feb 18 '13 at 07:54
  • 2
    @mahdi, yes ! it is possible. listview in your Menu is treated same as a normal list-view that you have on your activity. So procedure is also same, just google for adding listener to listview and replace name of that list-view with your list-view, and you are done ! – Saurabh Bayani Feb 18 '13 at 08:02
  • 1
    @SaurabhBayani , i use this code to add items to my ListViews (menu & Main Screen) but it`s only work for main screen ! – mahdi Feb 18 '13 at 10:17
0

I believe you imported the package with a different package name.

The declared package "com.slidingmenu.lib.app" does not match the expected package "library.src.com.slidingmenu.lib.app"

Rename it from com.slidingmenu.lib.app to library.src.com.slidingmenu.lib.app and see if that resolves the problem.

Kirk
  • 16,182
  • 20
  • 80
  • 112
0

you need only import the project inside the "library" folder

Rodrigo Amaro Reveco
  • 4,932
  • 5
  • 22
  • 33
  • Can you be little more specific ? i mean there are many folder in that zip folder, which one should i import in my lib folder ? – john44 Dec 27 '12 at 19:48
  • like @john44 told you, unzip the SlidingMenu from jFeinStein and import just the folder "library" from the unzipped folder. Define it as a library in the propreties and import it in your project. It might be usefull, to import the Example too for better understanding of the different possibilities, but to be true, for the beginning It might be too confusing and better to go the way just explained at the top. – Alex Cio Mar 09 '13 at 22:51
0

i use this code to add items to my ListViews (menu & Main Screen) but it`s only work for main screen

final Context context = this ;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView lv = (ListView) findViewById(R.id.listView1);
    String[] items = new String[]{"xxx","xxx","xxx","xxx"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context ,android.R.layout.simple_list_item_1, android.R.id.text1, items); 
    lv.setAdapter(adapter);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.menu_frame, null);
    ListView lv2 = (ListView) view.findViewById(R.id.listView2);
    TextView tv2 = (TextView) view.findViewById(R.id.textView2);
    tv2.setText("Hello Mahdi");
    String[] items2 = new String[]{"xxx","xxx","xxx","xxx"};
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(context ,android.R.layout.simple_list_item_1, android.R.id.text1, items2); 
    lv2.setAdapter(adapter2);


    SlidingMenu menu;
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidth(5);
    menu.setFadeDegree(0.0f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setBehindWidth(200);
    menu.setMenu(R.layout.menu_frame);
}
mahdi
  • 16,257
  • 15
  • 52
  • 73