Android_侧滑页面传值Fragment
来源:互联网 发布:mac适用的办公软件 编辑:程序博客网 时间:2024/06/05 15:09
第一:布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout android:id="@+id/drawerlayout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="activity.example.com.drawerlayout.MainActivity">
<FrameLayout android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent"/> <!--和drawerLayout配合需要配这两个属性android:layout_gravity="left" android:choiceMode="singleChoice" --><ListView android:id="@+id/listview" android:layout_width="200dp" android:layout_height="match_parent" android:layout_gravity="left" android:choiceMode="singleChoice" /></android.support.v4.widget.DrawerLayout>第二:Fragment中public class Fragment1 extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { TextView textView = new TextView(getActivity()); Bundle bundle = getArguments(); String text = bundle.getString("text"); textView.setText(text); return textView; }}第三:代码public class MainActivity extends AppCompatActivity { private ListView listview; private DrawerLayout drawerlayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout); listview = (ListView) findViewById(R.id.listview); final ArrayList<String> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { list.add("DrawerLayout" + i); } ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, list); listview.setAdapter(adapter); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Fragment1 fragment1 = new Fragment1(); Bundle bundle = new Bundle(); bundle.putString("text", list.get(i)); fragment1.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,fragment1).commit(); //关闭侧滑页面 drawerlayout.closeDrawer(listview); } }); }}
阅读全文
1 0
- Android_侧滑页面传值Fragment
- Android_侧滑页面需要添加的属性
- Android_自定义View、Fragment
- Android_动态加载Fragment
- Android_侧滑菜单
- Android_手机信息页面
- android_判断网络/添加Fragment显示listview
- Android_静态添加Fragment&RadioButton切换
- Fragment页面之间传值、基本例子演示、生命周期、兼容性
- Android_自定义控件_ListView侧滑删除
- Android_页面之间的数据传递
- Android_接口回传
- android_使用ViewPager和Fragment实现滑动导航
- Android_横向滑动菜单, HorizontalScrollView,Fragment,Viewpager结合使用
- Android_横向滑动菜单, HorizontalScrollView,Fragment,Viewpager结合使用
- Android_侧滑/横向滚动/XlistView上下/ViewPager-fragment/头布局/
- Android_横向滑动菜单, HorizontalScrollView,Fragment,Viewpager结合使用 +pullToRefreshListView
- fragment页面刷新
- 【valid-palindrome】
- 安卓广播监听电量
- 微信小程序----组件之textarea
- 关于python中字典的一些总结
- 【Selenium】14Cookie
- Android_侧滑页面传值Fragment
- jdk
- MPOS银行卡磁条信息加密规范
- mongodb Replica Sets +Sharding高可用集群搭建(含认证)
- 已经为元素 "web-app" 指定属性 "xmlns"
- 面向对象(典型)
- Java基础——Servlet(六)分页相关
- 当前企业财务报表分析存在的问题
- uboot中TFTP协议的原理