adamrocker / simple-side-drawer Goto Github PK
View Code? Open in Web Editor NEWSimple library which enable you to add a drawer(slide-out) navigation to your android application
Simple library which enable you to add a drawer(slide-out) navigation to your android application
Following exception was thrown when mAboveView.addView(above) called on setBehindContentView() method.
01-27 20:55:25.222: W/System.err(5964): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
01-27 20:55:25.226: W/System.err(5964): at android.view.ViewGroup.addViewInner(ViewGroup.java:3337)
01-27 20:55:25.226: W/System.err(5964): at android.view.ViewGroup.addView(ViewGroup.java:3208)
01-27 20:55:25.250: W/System.err(5964): at android.view.ViewGroup.addView(ViewGroup.java:3165)
01-27 20:55:25.250: W/System.err(5964): at android.view.ViewGroup.addView(ViewGroup.java:3145)
01-27 20:55:25.250: W/System.err(5964): at com.navdrawer.SimpleSideDrawer.setBehindContentView(SimpleSideDrawer.java:137)
This error does not occur on demo example application. I don't know why.
Anyway, it seems that the modification of SimpleSideDrawer.java on commit e066e1e is not needed because mAboveView was completely prepared on constructor.
It works well if I erase the modification.
Thank you for your useful OSS.
Can you add more example code(easy tutorial) for a beter layout Like the screenshots? I've got the library working but it looks kinda weird.
Van you add more example code for a beter layout Luke the screenshots? I've bot the library workibg but it looks Linda weird.
I want to menu layout to be open from top instead of left or right and close it to downwards...Is this possible??
I succesfully added the drawer.
But the problem is drwer items dont respond to onclicks.
`LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final SimpleSideDrawer mNav = new SimpleSideDrawer(this);
mNav.setRightBehindContentView(R.layout.navigation);
View v = inflater.inflate(R.layout.navigation, null);
Button buton = (Button) v.findViewById(R.id.buton);
buton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("buton", "clicked");
}
});`
Code seems fine but onclick does not called.
Thanks in advance.
Hi,
I am trying to open left side bar when I will frag from left to right like google when side bar is closed.
Can you please guide me how to do it.
Now sidebar is closing and opening iwith dragging is possible when side bar is open.
Hi, I am using simple-side-drawer with fragment, first time its render contents but after pop fragment, when I again render that fragment that I have pop, its give me exception. you can see that exception below
`
syncDispatchLocalHits timed out: java.util.concurrent.TimeoutException
E/UncaughtException: java.lang.ClassCastException: android.view.View cannot be cast to android.view.ViewGroup
at com.navdrawer.SimpleSideDrawer.(SimpleSideDrawer.java:240)
at com.navdrawer.SimpleSideDrawer.(SimpleSideDrawer.java:193)
at browseactivitiesreeboks.BrowseActivitiesByCatagoryActivity.setUpViews(BrowseActivitiesByCatagoryActivity.java:127)
at browseactivitiesreeboks.BrowseActivitiesByCatagoryActivity.onCreateView(BrowseActivitiesByCatagoryActivity.java:104)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
throwable java.lang.ClassCastException: android.view.View cannot be cast to android.view.ViewGroup
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.istar.reebok.reeboks, PID: 2011
java.lang.ClassCastException: android.view.View cannot be cast to android.view.ViewGroup
at com.navdrawer.SimpleSideDrawer.(SimpleSideDrawer.java:240)
at com.navdrawer.SimpleSideDrawer.(SimpleSideDrawer.java:193)
at browseactivitiesreeboks.BrowseActivitiesByCatagoryActivity.setUpViews(BrowseActivitiesByCatagoryActivity.java:127)
at browseactivitiesreeboks.BrowseActivitiesByCatagoryActivity.onCreateView(BrowseActivitiesByCatagoryActivity.java:104)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)`
how to handle that exception, please help me
Regards
Munir Ahmad
where is the simple-side-drawer2 ,you share the url can not be opened.
thank you to share the library about the simple-side-drawer2
Please add function in actionbar icon.. if i pressed it need to open the leftdrawer. Thanks great work
Hello, I'm trying to call a different class within the side menu layout. Is that possible?
package com.ure.h22h.views;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.R.integer;
import android.app.Activity;
import android.content.ClipData.Item;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.flurry.android.FlurryAgent;
import com.google.android.gcm.GCMRegistrar;
import com.navdrawer.SimpleSideDrawer;
import com.ure.h22h.R;
import com.ure.h22h.utils.Consts;
import com.ure.h22h.utils.MainListAdapter;
import com.ure.library.MyGenericListener;
import com.ure.library.model.AzureHelper;
import com.ure.library.model.Folder;
import com.ure.library.model.GcmHelper;
import com.ure.library.model.ViewHelper;
import eu.inmite.android.lib.dialogs.ISimpleDialogListener;
/**
public class Main extends FragmentActivity implements ISimpleDialogListener,OnClickListener
{
private boolean _fansPage=false;
private List<Map<String, Object>> _items;
private SimpleSideDrawer _navigation;
private MainListAdapter MainListAdapter;
@OverRide
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initNavigation();
initMenu();
//顯示首頁Fragment
contrlFragment(0);
countNewList();
}
//設定導覽
private void initNavigation() {
Log.d("ted", "initNavigation");
_navigation = new SimpleSideDrawer(this);
_navigation.setLeftBehindContentView(R.layout.navigation_content);
findViewById(R.id.menu).setOnClickListener(this);
}
//預設選單設定
private void initMenu() {
Log.d("ted", "initNavigation");
_items = new ArrayList<Map<String,Object>>();
String[] menuName = getResources().getStringArray(R.array.menu_name);
int[] image = {
R.drawable.icon_star, R.drawable.icon_story, R.drawable.icon_shop,
R.drawable.icon_activity, R.drawable.icon_food, R.drawable.icon_goods,
R.drawable.icon_trip, R.drawable.icon_view, R.drawable.icon_bookmark
, R.drawable.icon_facebook
};
//Menu圖片與文字
for (int position = 0; position < menuName.length; position++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("Text", menuName[position]);
item.put("Image", image[position]);
item.put("New", "0");
_items.add(item);
}
ListView _listView = (ListView) _navigation.findViewById(R.id.menu_list);
MainListAdapter = new MainListAdapter(this,_items,image);
_listView.setAdapter(MainListAdapter);
_listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
contrlFragment(position);
_navigation.closeLeftSide();
}
});
}
//檢查是否有新東西並且顯示
private void countNewList() {
new ViewHelper(this).getFoldersAsync(new MyGenericListener<ArrayList<Folder>>() {
@Override
public void onComplete(ArrayList<Folder> eventData) {
try {
final int[] folderID = getResources().getIntArray(R.array.lib_setting_folderList);
for (int pos = 0; pos < eventData.size(); pos++){
for (int i = 0; i < folderID.length; i++) {
if(eventData.get(pos).getFolderID()==folderID[i]){
Map<String, Object> item = new HashMap<String, Object>();
item.put("Text", _items.get(i).get("Text"));
item.put("Image", _items.get(i).get("Image"));
item.put("New", eventData.get(pos).getContentCount_new().toString());
_items.set(i, item);
}
}
}
MainListAdapter.notifyDataSetChanged();
} catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void onError(ArrayList<Folder> eventData) {
// TODO Auto-generated method stub
}
});
}
//控制各分類fragment
private void contrlFragment(int position) {
Log.d("ted", String.valueOf(position));
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Bundle data = new Bundle();
switch (position) {
case 0://首頁
fragmentTransaction.replace(R.id.main_pager, new FHome()).commitAllowingStateLoss();
_fansPage = false;
break;
case 9://粉絲團
data.putString("Link", "https://m.facebook.com/tainan1616");
data.putString("Title", "加入粉絲");
FWebView FWebView = new FWebView();
FWebView.setArguments(data);
fragmentTransaction.replace(R.id.main_pager,FWebView).commitAllowingStateLoss();
_fansPage = true;
break;
default://預設
Fragment CurrentFragment =null;
CurrentFragment = new FMain();
data.putInt("CurrentPage", position);
CurrentFragment.setArguments(data);
fragmentTransaction.replace(R.id.main_pager, CurrentFragment).commitAllowingStateLoss();
_fansPage = false;
break;
}
}
// 註冊 Android 設備,以便日後可以收到 PUSH 訊息
private void registerDevice(boolean allowPush) {
// 先儲存是否願意收到PUSH狀態,之後才能傳到 Server
new ViewHelper(this).setPushState(allowPush);
// 註冊 Android 設備,以便日後可以收到 PUSH 訊息
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
String registationId = GCMRegistrar.getRegistrationId(this);
if (registationId.equals(""))
GCMRegistrar.register(this, Consts.GOOGLE_API_SENDERID);
else {
AzureHelper azureHelper = new AzureHelper(this);
azureHelper.registerDevice(registationId, allowPush);
}
}
private void registerDevice2(boolean allowPush) {
// 先儲存是否願意收到PUSH狀態,之後才能傳到 Server
new ViewHelper(this).setPushState(allowPush);
// 註冊 Android 設備,以便日後可以收到 PUSH 訊息
GcmHelper helper = new GcmHelper(this.getApplicationContext());
helper.startRegister(allowPush);
}
@Override
public void onBackPressed()
{
//網頁的BACK跟程式的BACK區分開來
// super.onBackPressed();
if(_fansPage)
FWebView.onBackPressed();
else
super.onBackPressed();
}
@Override
protected void onStart()
{
super.onStart();
// FlurryAgent.setLogLevel(Log.VERBOSE);
FlurryAgent.onStartSession(this, Consts.FLURRY_KEY);
}
@Override
protected void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
}
/*
* 接收附屬Fragment中的DialogFragment裡的requestCode
* 不可寫在附屬的Fragment中會接收不到
*/
@Override
public void onPositiveButtonClicked(int requestCode) {
switch (requestCode) {
case 10:
registerDevice2(true);
break;
case 11:
final String PackgeParam = "com.ure.h22h";
try{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+PackgeParam)));
}
catch (android.content.ActivityNotFoundException anfe){
// Open Google Play website
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+PackgeParam)));
}
break;
case 12:
//do nothing
break;
case 13:
//do nothing
break;
}
}
@Override
public void onNegativeButtonClicked(int requestCode) {
switch (requestCode) {
case 10:
registerDevice2(false);
break;
}
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.menu:
_navigation.toggleLeftDrawer();
break;
}
}
}
this my code
first time usually is empty
Hey
First of all, thanks for sharing your app menu drawer implementation.
OK. I want to creat the menu like app of path on ios . that have two menu for left and right in the mainactiviy in the theam time.
But in your code,This is currently not possible, you just have only one for left menu.
how to do that ?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.