baidu_29663457
baidu_29663457
采纳率0%
2015-07-25 02:06 阅读 2.3k

我想请大神帮我看看这个安卓开发的问题,我想实现自制侧滑菜单,然后我点击左边菜单按钮,界面不跳转啊

ackage com.wecampus.slidingmenu;

import com.imooc.slidingmenu.R;
import com.wecampus.slidingmenu.view.SlidingMenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;

public class MainActivity extends Activity
{

private SlidingMenu mLeftMenu ; 

@Override
protected void onCreate(Bundle savedInstanceState)
{
    requestWindowFeature(Window.FEATURE_NO_TITLE); // 无标题
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mLeftMenu = (SlidingMenu) findViewById(R.id.id_menu);
}

public void toggleMenu(View view)
{
    mLeftMenu.toggle();
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}
图片说明


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • baidu_29663457 baidu_29663457 2015-07-25 02:08
     package com.wecampus.slidingmenu.fragment;
    
    import com.imooc.slidingmenu.R;
    import com.wecampus.slidingmenu.MainActivity;
    
    import android.app.Activity;
    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.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.View.OnClickListener;
    
    public class LeftFragment extends FragmentActivity implements OnClickListener{
    
        private View mapView;
        private View liveView;
        private View moreView;
        private View lineView;
        private View collectionView;
        private View scheduleView;
    
        private Fragment mMap;
        private Fragment mLine;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
    
        public void onAttach(Fragment activity) {
            super.onAttachFragment(activity);
        }
    
    
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.left_menu, container, false);
            findViews(view);
            return view;
        }
    
        public void findViews(View view) {
            // TODO Auto-generated method stub
            mapView = view.findViewById(R.id.w_map);
            lineView = view.findViewById(R.id.w_line);
    
            mapView.setOnClickListener(this);
            lineView.setOnClickListener(this);
        }
    
    
         /*public void onDestroyView() {
              super.onDestroyView();
        }
    
    
         public void onDestroy() {
              super.onDestroy();
        }
    */
    
        public void onClick(View v) {
    
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            hideFragment(transaction);
            String title = null;
            /*switch (v.getId()) {
            case R.id.w_map: 
                MapFragment mapfragment=new  MapFragment();
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                beginTransaction.add(R.id.id_menu, mapfragment);
                beginTransaction.addToBackStack(null);
                beginTransaction.commit();
                break;
            }
            */
            switch (v.getId()) {
            case R.id.w_map: // 校园地图
                if (mMap == null)
            {
                mMap = new MapFragment();
                transaction.add(R.id.content_frame, mMap);
            } else
            {
                transaction.show(mMap);
            }
    
                title = getString(R.string.map);
                break;
            case R.id.w_line:// 路线查询
                if (mLine == null)
                {
                    mLine = new MapFragment();
                    transaction.add(R.id.content_frame, mLine);
                } else
                {
                    transaction.show(mLine);
                }
    
                title = getString(R.string.line);
                break;
            default:
                break;  
    
    
    
        }
    
            transaction.commit();
    
    
        }
    
    
        private void hideFragment(FragmentTransaction transaction) {
            // TODO Auto-generated method stub
    
        }
    
    
        }
    
    
    点赞 评论 复制链接分享
  • Evankaka Evankaka 2015-07-25 04:04

相关推荐