0

現在、いくつかのスワイプページがあり、それらすべてに異なるデータのリストが必要です。
私はまだAndroidにかなり慣れていないので、思いつく可能性のあるすべてのオプションを試しました:

  1. 最初に、ページの内部にいくつかの xml レイアウトを追加してみました。
  2. 次に、実用的にリストを作成して入力しようとしました。

上記のどれも私にとってはうまくいきませんでした。

手始めに、概念を理解しているかどうかを確認したいと思います。スワイプレイアウトにはページが含まれており、データはタイプコンテンツ
によってページに渡される可能性があります。getItem() Fragment

そして今、私が望むものを達成する方法:
を追加し、最後にその要素の子を私のメインページテンプレートに追加し、データ入力メソッドを作成する必要があります。LinearLayoutListViewTextViewlayout/main.xml

私の推論に何か問題があり、それが原因で答えが見つからないのですか、それとも正しい情報源が見つからないのですか?

コード例:
main.xml

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <!--
    This title strip will display the currently visible page title, as well as the page
    titles for adjacent pages.
    -->

    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" />

</android.support.v4.view.ViewPager>

list_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

MainActivity.java

...    
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Create the adapter that will return a fragment for each of the three primary sections
        // of the app.

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());


        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

    }
...
4

1 に答える 1

0

listview.xmlこれを行うには、.xmlを定義するxml を宣言しますListViewTextViewプログラムで新しいレイアウトを作成するか、たとえばをtitleview.xml使用してタイトル ビューを書き込む新しいレイアウトを作成できますTextView

プログラムで両方のビューを拡張し、メイン レイアウトの親ビューをこれらの子ビューの親として渡すことができます。

    LayoutInflater inflater = getLayoutInflater();
    ListView listview = inflater.inflate(R.layout.list_view, parent);
    TextView textview = inflater.inflate(R.layout.textview, parent);
    layout.addView(textview);
    layout.addView(listview);
于 2012-09-20T19:31:17.830 に答える