1

withMainActivityを作成するアプリがあります(これに使用されます)。ActionBartabsActionBarSherlock

それぞれtabがをロードしFragmentます。1つのフラグメントには、ListViewアイテムをロードするがあります。各アイテムはイベントに応答しOnItemClickます。

アイテムがクリックされると、アプリはWebサーバーからデータを取得します。そのデータを新しいで表示したいと思いListViewます。しかし、それは私が立ち往生しているところです。

ListView最初のメインから「サブリストビュー」に切り替えるにはどうすればよいですか?

私の現在のビューはフラグメントであり、タブ内にロードされていることに注意してください。新しい'sub'を表示するときに、同じタブに留まりたいですListView

また、Androidデバイスを押し戻すと、メインが再びbutton表示されるようにしたいと思います。ListView

だから実際には、iPhoneのように彼らのでそれをしTableViewます。

4

1 に答える 1

1

You have te use another Fragment in order to do that. You need to create that Fragment and then replace the old one with the FragmentTransaction and if you want to use the "back" button you need to add the new fragment to the Backstack. If these ListFragment are quite different in terms of data, I'd have 2 fragment classes (e.g. : FirstListFragment, SecondListFragment).

Here's some code from an App I worked on :

    // Here I get the FragmentTransaction

    FragmentTransaction ft = getFragmentManager().beginTransaction();

    // I replace it with a new Fragment giving it data. Here you need to tell 
    // the FragmentTransaction what (or actually where) and by what you want to replace. 

    ft.replace(R.id.fraglist, new ModuleFragment(lpId, sqId, sqName));

The R.id.fraglist should be defined in your XML layout (except if you programmatically created your layout). It's simply the ID of your default fragment.

    // I set the animation

    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    // I add it to the backstack so I can use the back button

    ft.addToBackStack(null);

    // Then I finally commit so it happens !

    ft.commit();

You can also use a Bundle to parse data like so :

    Bundle moduleBundle = new Bundle();
    moduleBundle.putString("id", id);
    moduleBundle.putString("description", description);
    moduleFragment.setArguments(moduleBundle);
于 2012-07-24T11:58:28.277 に答える