片段中的ActionbarSherlock片段

时间:2012-06-28 11:49:00

标签: android android-fragments android-actionbar actionbarsherlock

我不知道这是我的应用程序结构的问题或我的代码有问题。

我有一个tabActivity,它扩展了SherlockFragmentActivity 它有一个ViewPager和一个TabsAdapter 有两个Tabs和一个OptionsMenu项目(“搜索”) 这两个选项卡用于输入搜索参数。一个简单,一个细节。如果单击搜索,则执行搜索并显示结果。

选项卡的内容已经是SherlockFragment类型的对象。到目前为止,这很好。

目前,搜索结果是一项单独的活动。我也希望将它们放在viewpager中。所以我将它转换为SherlockActivity。但是如果我在onCreate()方法中创建(“this”是tabActivity):

FragmentManager fm = this.getSupportFragmentManager();
Fragment ft = Fragment.instantiate(this, searchFragment.class.getName(), null);
if(fm.findFragmentById(R.id.searchresults_content) == null)
{
    fm.beginTransaction().add(R.id.searchresults_content, ft).commit();
}

然后:

this.mViewPager.addView(ft.getView());

ft.getView();返回null。来自searchFragment的OnCreateView将执行此操作:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    WebView mWebView = (WebView)findViewById(R.id.search_results);
    View mView = inflater.inflate(R.layout.search_results, container, false);
    mWebView.setWebViewClient(new SearchResultsWebViewClient());
//... (load data for webview etc...)
    return mView;
}

search_results.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"> 
    <WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id ="@+id/search_results"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </WebView>
</LinearLayout>

0 个答案:

没有答案