侧拉菜单传值
来源:互联网 发布:java file.getlength 编辑:程序博客网 时间:2024/06/15 14:12
XML布局<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <!--主内容区域的视图--> <FrameLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> <!--抽屉展示的布局--> <RelativeLayout android:background="#ffffff" android:layout_gravity="left" android:id="@+id/relative_layout" android:layout_width="200dp" android:layout_height="match_parent"> <ImageView android:id="@+id/image" android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/ic_launcher" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" /> <ListView android:layout_marginTop="20dp" android:id="@+id/list_view" android:layout_below="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </RelativeLayout></android.support.v4.widget.DrawerLayout>主页面public class MainActivity extends AppCompatActivity { private DrawerLayout drawerLayout; private RelativeLayout relativeLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //抽屉的跟布局 drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); //选项的菜单 ListView listView = (ListView) findViewById(R.id.list_view); //主内容区域的布局 FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frame_layout); //抽屉显示的布局 relativeLayout = (RelativeLayout) findViewById(R.id.relative_layout); final List<String> list = new ArrayList<>(); list.add("首页"); list.add("要闻"); list.add("我的"); //设置适配器 ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, list); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //要有一个fragment替换后面主内容的frameLayout Fragment01 weiXinFragment = new Fragment01(); //传值过去 Bundle bundle = new Bundle(); bundle.putString("key",list.get(i)); weiXinFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,weiXinFragment).commit(); //关闭抽屉 drawerLayout.closeDrawer(relativeLayout); } }); }}Fragment页面public class Fragment01 extends Fragment { private TextView textView; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment01, container, false); textView = (TextView) view.findViewById(R.id.text); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //获取到传递过来的页码 Bundle bundle = getArguments(); String pageNum = bundle.getString("key","1"); Log.i("------233----",bundle.toString()); textView.setText(pageNum); //获取数据 }}
阅读全文
0 0
- 侧拉菜单传值
- drawerlayout 侧拉菜单 点击传值,Fragment
- ios侧拉菜单
- 63.侧拉菜单
- SlidingMenu侧拉菜单
- 侧拉菜单
- 侧拉菜单
- SlidingPaneLayout:侧拉菜单
- slidingmenu侧拉菜单
- 侧拉新闻菜单
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单显示
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单
- 侧拉菜单(SlidingMenu)
- 侧拉菜单
- C/C++中 变量的存储位置
- Nginx 启动步骤
- 【解决】postman调试oAuth2.0第三方接口
- HttpServletRequest介绍
- 微信退款结果通知报文AES解密
- 侧拉菜单传值
- springmvc的ModelAttribute注解
- To enable just-in-time (JIT) debugging错误的解决方式
- Linux 命令之查看和修改机器名称
- Intellij idea使用小坑
- ViewPager中Fragment的生命周期
- opencv开发笔记(十):利用轨迹条调整图像对比度和亮度
- MacOS 开发 -- 程序打包生成dmg
- Lua table 表的操作——只有代码