I have two ListView and I want them to share the same layout position so when I click a button one ListView hides. Maybe this is not possible or there is a better way like fragments?
Use FrameLayout
. This layout view overlies two views over each other.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</FrameLayout>
For showing the first page (ie the first ListView
):
findViewById(R.id.list1).setVisibility(View.VISIBLE);
findViewById(R.id.list2).setVisibility(View.GONE);
And for the second page:
findViewById(R.id.list1).setVisibility(View.GONE);
findViewById(R.id.list2).setVisibility(View.VISIBLE);
fragments are the easy way to do this IF you don't plan on changing the data in your views.
Make a button and
/*create fragment of the opposite view, probably through a boolean field and an if block
then*/
getSupportFragmentManager.beginTransaction().replace(/*your fragments*/).commit().
in your onclicklistener.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.