ListFragment不同布局布局、不同、ListFragment

由网友(啦啦啦~我是卖报的小行家)分享简介:我的工作片段,ListView和具有输出,显示图像。每点击改变fragment2.till的TextView的还行。I am working on Fragment-ListView and having output showing in image.every Click changes TextView o...

我的工作片段,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.

感谢你。

阅读全文

相关推荐

最新文章