动作条选项卡 - 替换列表片段的细节片段 [英] ActionBar tab - replace list fragment with detail fragment
问题描述
我挣扎组合的标签动作条和片段
我用 ActionBarSherlock 以显示三个独立的选项卡,我的问题是关于独占第一个选项卡。它应该显示在列表和详细视图相结合的项目(称为券)。另外两个选项卡显示不同的内容,并没有在这方面发挥的作用。
我在做什么是以下内容:
- 主要活动三个选项卡,将创建三个片段
- 选项卡(名单片段)填充,并呈现名单
- 对于列表上点击我写在接收单击项目的id和交换清单片段与细节片段选项卡上的主要活动回调(至少它应该这样做)
- 在回调创建要被显示的细节片段,并尝试用它来取代列表片段。
不幸的是我没有获得超越:
java.lang.IllegalArgumentException:如果没有查看发现ID 0x7f040027 对于片段CouponDetailFragment {44f4e310#1 ID = 0x7f040027}
我附上相关片段会在问题结束。任何帮助是非常AP preciated。
这些都是相关的片段:
公共类MyCouponActivity扩展SherlockFragmentActivity实现CouponListFragment.Callbacks
清单片段:
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android 的xmlns:工具=http://schemas.android.com/tools 机器人:名称=foo.bar.CouponListFragment 机器人:ID =@ + ID / coupon_list 机器人:layout_width =match_parent 机器人:layout_height =match_parent/>
交易片段交换:
@覆盖
公共无效onItemSelected(最后弦乐ID){
最后的捆绑参数=新包();
arguments.putString(CouponDetailFragment.ARG_ITEM_ID,ID);
最后CouponDetailFragment片段=新CouponDetailFragment();
fragment.setArguments(参数);
。getSupportFragmentManager()的BeginTransaction()代替(R.id.coupon_list,片段).commit();
}
如果你定义XML片段,它是固定的,你不能用在FragmentTransaction另一个片段取代它。
您最好的选择是,以取代<片段/>
带有某种的ViewGroup
的。不要忘了,那么你就必须使用FragmentTransaction添加CouponListFragment在的onCreate(..)
您的活动。
I'm struggling combining a tabbed ActionBar and fragments.
I'm using ActionBarSherlock to display three independent tabs, and my problem relates to the first tab exclusively. It's supposed to display items (called "coupons") in a combination of list and detail view. The other two tabs display different content and do not play a role here.
What I'm doing is the following:
- The main activity creates three fragments for three tabs
- Tab A (a list fragment) populates and renders its list
- For clicks on the list I wrote a callback in the main activity that receives the clicked item's id and exchanges the list fragment with the detail fragment on the tab (at least its supposed to do so)
- In that callback I create the to-be-displayed detail fragment and try to replace the list fragment with it.
Unfortunately I dont get beyond:
java.lang.IllegalArgumentException: No view found for id 0x7f040027 for fragment CouponDetailFragment{44f4e310 #1 id=0x7f040027}
I attached the relevant snippets at the end of the question. Any help is highly appreciated.
These are the relevant snippets:
public class MyCouponActivity extends SherlockFragmentActivity implements CouponListFragment.Callbacks
List fragment:
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:name="foo.bar.CouponListFragment" android:id="@+id/coupon_list" android:layout_width="match_parent" android:layout_height="match_parent" />
Transaction for fragment exchange:
@Override
public void onItemSelected(final String id) {
final Bundle arguments = new Bundle();
arguments.putString(CouponDetailFragment.ARG_ITEM_ID, id);
final CouponDetailFragment fragment = new CouponDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().replace(R.id.coupon_list, fragment).commit();
}
If you define a fragment in XML, it is fixed and you can't replace it with another fragment in a FragmentTransaction.
Your best bet would be to replace the <fragment />
with some sort of ViewGroup
. Don't forget then you'd have to use a FragmentTransaction to add a CouponListFragment in the onCreate(..)
of your Activity.
这篇关于动作条选项卡 - 替换列表片段的细节片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!