ListFragment不同布局 [英] ListFragment with different Layout

查看:282
本文介绍了ListFragment不同布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作片段,ListView和具有输出,显示图像。 每点击改变fragment2.till的TextView的还行。

I am working on Fragment-ListView and having output showing in image. every Click changes TextView of fragment2.till now ok.

fragmetn1是ListView和fragment2是DifferentView。

fragmetn1 is for listView and fragment2 is for DifferentView.

现在我想改变布局fragment2与点击。例如作为ITEM2被点击时,与TextView的布局设置在fragment2。现在选择项目3中,巴顿diferent布局应设置为fragment2。

now i want to change layout in fragment2 with click. e.g. as item2 is clicked,a layout with textView sets in fragment2. now with selection of item3, diferent layout with Button should be set to fragment2.

我getView code是在这里。

my getView code is here.

public void onListItemClick(ListView l, View v, int position, long id) {

        DetailFrag frag = (DetailFrag) getFragmentManager().findFragmentById(R.id.frag_detail);

        if (frag != null && frag.isInLayout()) {
            frag.setText("item "+position+" selected");
        }
    }

有没有其他办法可以做到这一点,PLZ也有助于这种方式。

任何建议是强烈的AP preciated.thanks提前。

any suggestion would be strongly appreciated.thanks in advance.

推荐答案

试试下面的方法

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

那么你需要的片段添加到此fragmentTransaction使用以下语法。

then you need to add your fragment to this fragmentTransaction with the following syntax.

fragmentTransaction.replace(R.id.detailFragment, layout1);

最后,你必须提交事务。否则,所做的更改不会持续。

And finally you MUST commit your transaction. Otherwise changes will not persist.

fragmentTransaction.commit();

有关简短的例子来看看这个博客帖子。我希望这会帮助你。

For brief example see this blog post. I hope This will help you.

感谢你。

这篇关于ListFragment不同布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆