現在、いくつかのスワイプページがあり、それらすべてに異なるデータのリストが必要です。
私はまだAndroidにかなり慣れていないので、思いつく可能性のあるすべてのオプションを試しました:
- 最初に、ページの内部にいくつかの xml レイアウトを追加してみました。
- 次に、実用的にリストを作成して入力しようとしました。
上記のどれも私にとってはうまくいきませんでした。
手始めに、概念を理解しているかどうかを確認したいと思います。スワイプレイアウトにはページが含まれており、データはタイプコンテンツ
によってページに渡される可能性があります。getItem()
Fragment
そして今、私が望むものを達成する方法:子
を追加し、最後にその要素の子を私のメインページテンプレートに追加し、データ入力メソッドを作成する必要があります。LinearLayout
ListView
TextView
layout/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);
}
...