Fragment之间的数据互传
来源:互联网 发布:苹果mac系统更新 编辑:程序博客网 时间:2024/04/29 20:20
public class LeftFragment extends Fragment { String[] menus = new String[]{"Android", "IOS", "WP"}; private OnClickItem onClickItem; public LeftFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view= inflater.inflate(R.layout.fragment_left, container, false); ListView lv= (ListView) view.findViewById(R.id.lv_menu); ArrayAdapter adapter=new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,menus); lv.setAdapter(adapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {// MainActivity activity= (MainActivity) getActivity();// activity.setContent(menus[position]); if (onClickItem != null) { onClickItem.setText(menus[position]); } } }); return view; } //自定义接口 public interface OnClickItem{ void setText(String msg); }
public class RightFragment extends Fragment { private TextView tv_content; public RightFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view=inflater.inflate(R.layout.fragment_right, container, false); tv_content= (TextView) view.findViewById(R.id.tv_content); return view; } public void set_content(String msg){ tv_content.setText(msg); }
public class MainActivity extends AppCompatActivity implements LeftFragment.OnClickItem{ private RightFragment rfg; private LeftFragment lfg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rfg= (RightFragment) getSupportFragmentManager().findFragmentById(R.id.fr_right); lfg = (LeftFragment) getSupportFragmentManager().findFragmentById(R.id.fr_left); //初始化LeftFragment 调用LeftFragment的set方法 }// public void setContent(String msg){// rfg.set_content(msg);// } @Override public void setText(String msg) { rfg.set_content(msg); }
0 0
- Fragment之间的数据互传
- Fragment与Fragment之间的数据交互
- Fragment与Fragment之间的数据传递
- Fragment之间的数据传递
- activity与fragment之间的数据交互
- fragment和activity之间的数据传递
- Fragment和Activity之间的数据传递
- Activity与Fragment之间的数据交换
- fragment与Activity之间的数据传递
- Fragment与Activity之间的数据传递
- Activity和Fragment之间的数据传递
- Fragment之间传递数据的方式
- Fragment与Activity之间的数据交互
- Fragment与Activity之间的数据交互
- fragment与Activity之间数据的传递
- actvity与fragment之间的数据传递
- Activity 和 Fragment 之间的数据传递
- Fragment和Activity之间的数据传递
- qt的环境搭建(一) Visual Studio
- 浅析java内存模型(JMM)
- HDU1171 Big Event in HDU
- IDEA 2016.3.4 创建Maven项目及部署发布
- 蓝桥杯 国王的烦恼(并查集)
- Fragment之间的数据互传
- Thinkphp 3.2 查询方法where()小结
- 两种方法在github中做在线Demo演示
- 如何在个人主页里插入音乐
- tensorflow 对Recursive NN的完美实现
- PL/SQL标准建表规范
- hdu 2546 饭卡 dp
- <spark>JavaAggregate,自定义数据处理
- 希尔排序