zoukankan      html  css  js  c++  java
  • 4月1日学习日志

    今天学习了侧滑菜单的使用。

    关键代码如下:

    public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
    
        private DrawerLayout drawer_layout;
        private ListView list_left_drawer;
        private ArrayList<Item> menuLists;
        private MyAdapter<Item> myAdapter = null;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
            list_left_drawer = (ListView) findViewById(R.id.list_left_drawer);
    
            menuLists = new ArrayList<Item>();
            menuLists.add(new Item(R.mipmap.iv_menu_realtime,"实时信息"));
            menuLists.add(new Item(R.mipmap.iv_menu_alert,"提醒通知"));
            menuLists.add(new Item(R.mipmap.iv_menu_trace,"活动路线"));
            menuLists.add(new Item(R.mipmap.iv_menu_settings,"相关设置"));
            myAdapter = new MyAdapter<Item>(menuLists,R.layout.item_list) {
                @Override
                public void bindView(ViewHolder holder, Item obj) {
                    holder.setImageResource(R.id.img_icon,obj.getIconId());
                    holder.setText(R.id.txt_content, obj.getIconName());
                }
            };
            list_left_drawer.setAdapter(myAdapter);
            list_left_drawer.setOnItemClickListener(this);
        }
    
    
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ContentFragment contentFragment = new ContentFragment();
            Bundle args = new Bundle();
            args.putString("text", menuLists.get(position).getIconName());
            contentFragment.setArguments(args);
            FragmentManager fm = getSupportFragmentManager();
            fm.beginTransaction().replace(R.id.ly_content,contentFragment).commit();
            drawer_layout.closeDrawer(list_left_drawer);
        }
    }
  • 相关阅读:
    java 容器
    Java容器有哪些?
    java容器---集合总结
    Java中的String,StringBuilder,StringBuffer三者的区别
    Socket心跳包机制
    JAVA实现简单的RPC框架
    redis、kafka、rabittMQ对比
    idea+maven无法自动加载jar包
    myeclipse 上安装 Maven3
    linux_开发软件安装=命令步骤
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883209.html
Copyright © 2011-2022 走看看