问题描述
这是一些$ C $工作c,我发现自己有点咸菜。
Working on some code, I found myself in a bit of a pickle.
我有片段,以显示我的应用程序的各个页面。我有,我想彼此交互的搜索片段和一个选项片段。是有可能具有可以正常存取,并将它用viewflipper访问的片段?
I have fragments to display the various pages of my app. I had a search fragment and an options fragment which I want to interact with one another. Is it possible to have a fragment which can be accessed normally and have it accessed using a viewflipper?
Options(选项)片段中有一个viewflipper,让我来显示参与其中的各种菜单。不过,我需要能够通过选项片段viewflipper访问搜索功能,同时也能够访问它作为一个正常的片段(不是在同一时间,但既能够通过选项卡上的片段进行访问酒吧或从选项片段viewflipper)。
The Options Fragment has a viewflipper in it which allows me to display the various menus that are involved with it. However, I need to be able to access the search function through the viewflipper on the Options Fragment, whilst also being able to access it as a normal Fragment (Not at the same time, but able to access it either via the fragment on the tab bar or from the viewflipper in the options Fragment).
到目前为止,我已经用下面的code激活viewflipper看法的变化:
So far I have used the following code to activate a viewflipper view change:
public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
if(moreViewFlipper.getChildAt(1) != null)//Check if any previously checked views
{
moreViewFlipper.removeViewAt(1);
}
switch(pos){
case 0: // Profile
moreViewFlipper.addView(createProfileView(ctx), 1);
moreViewFlipper.setInAnimation(SlideAnimation.inFromRightAnimation());
moreViewFlipper.setOutAnimation(SlideAnimation.outToLeftAnimation());
moreViewFlipper.setDisplayedChild(1);
break;
...
是否可以使用code以上(加上片段的观点,作为一个孩子的moreViewFlipper?我将不胜感激,如果有人可以帮助我。
Is it possible to use the code above (adding the fragment's view as a child to the moreViewFlipper? I would be grateful if anyone could help me with this.
编辑:
一个朋友很慈祥设法指出,我怎么可能经过一些实验做到这一点。显然,这是可能的,如果你把它在保持你希望的片段添加到视图的XML文件放置在视图中的片段。
A friend very kindly managed to point out how I could do this after some experimentation. Apparently, it is possible to place a fragment within a view if you place it in the the xml file which holds the view which you wish to add the fragment to.
在这种情况下,我创建了一个新的XML文件,并放置在片段的Linearview内有后退按钮。我用上面的code调用哪个膨胀的观点和将其纳入viewflipper和voala功能!它只要你有一个不同的ID为您的片段作为你原来做的(如果是像我这样的情况下,被称为在两个实例)的作品。
In this case, I created a new xml file and placed the fragment inside a Linearview with a back button. I used the code above to call a function which inflated the view and brought it into the viewflipper and voala! it works as long as you have a different ID for your fragment as you do for the original one (if it is a case like mine, being called in 2 instances).
再次抱歉浪费别人的时间,但感谢你的好意。
Again, sorry for wasting people's time, but thank you for your kindness.
推荐答案
对不起,我迟到的反应。但其他人可能是有人有类似的问题。
Sorry for the late response. But may be someone else has a similar issue.
可以,如果你使用的是ViewPager结合ViewFlipper和片段。把ViewPager -node您ViewFlipper -node里面你main_layout.xml。操作栏仍然会留在它的地方,你就可以翻转到另一种观点很容易和倒退。
You can combine ViewFlipper and Fragments if you are using ViewPager. Put ViewPager -node inside your ViewFlipper -node in your main_layout.xml. The action bar will still stay on its place and you will be able to flip to the other view easily and backwards.
如果你想处理一个硬件后退按钮,把类似的东西在你的主片段活动:
If you want to handle a hardware back button, put something like that in your main fragment activity:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
if(this.vf.getCurrentView() != this.findViewById(R.id.pager)) //vf is a ViewFlipper's instance
{
this.vf.showPrevious();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
这篇关于安卓:可以将片段添加到Viewflipper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!