0

アプリケーション構造の問題なのか、コードの問題なのかわかりません。

SherlockFragmentActivity を拡張する tabActivity があります。
これには ViewPager と TabsAdapter があります。
2 つのタブと 1 つの OptionsMenu 項目 (「検索」) があります。
2 つのタブは、検索パラメーターを入力するためのものです。1 つはシンプル、もう 1 つは詳細です。検索をクリックすると、検索が実行され、結果が表示されます。

タブのコンテンツは、すでに SherlockFragment 型のオブジェクトです。これまでのところ、これはうまくいきます。

現時点では、検索結果は別のアクティビティです。それらをviewpagerにも入れたいと思います。だから私はそれをSherlockActivityに変換しました。しかし、onCreate() メソッドで作成した場合 (「これ」は 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;
}

検索結果.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>
4

0 に答える 0