0
ActivityGroupsの代わりにFragmentsを使用するように私のソリューションを変更してみました。その上にあるListViewに応じて私のUIの一部を変更できる例が見つかりました。私がしたいのは、アイテムがクリックされたときに新しいレイアウトのみが表示されるようにアイテムをクリックすると、それ自体を置き換えるListViewを持つことです。これは可能ですか?フラグメントをビューに置き換える
あなたは、私が使用しています関連するコードの例を参照してくださいよ下:
public class FragmentTestActivity extends FragmentActivity implements OnItemClickListener
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView l = (ListView) findViewById(R.id.number_list);
ArrayAdapter<String> magzTitles = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1,
new String[]{"Cupcake",
"TaberTHULE",
"Lite"});
l.setAdapter(magzTitles);
l.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Fragment testFragment = new TestFragment(position++);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.the_frag, testFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
}
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frags"
>
<ListView
android:id="@+id/number_list"
android:layout_width="150dp"
android:layout_height="match_parent"
/>
<fragment class="com.android.saket.fragments.TestFragment"
android:id="@+id/the_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
リストビューもフラグメントでなければなりませんか? – CodePrimate
私は単に私がしようとしていることをしている例を見つけることができませんでした。あなたが私にリンクを提供する可能性がありますか? – CodePrimate
リストビューはフラグメントである可能性がありますが、それはリストフラグメント内にあるため、そうである必要はありません。以下は、正しいと思われるものへのリンクです:http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.html – Warpzit