开发者

Android: on swipe switch between Views / Activities / Fragments

开发者 https://www.devze.com 2023-04-01 04:02 出处:网络
I\'m implementing a chat a开发者_JAVA百科pplication. The user is able to have multiple chats open simultaneously, and I want to allow him to switch between these chats with swiping left or right. Like

I'm implementing a chat a开发者_JAVA百科pplication. The user is able to have multiple chats open simultaneously, and I want to allow him to switch between these chats with swiping left or right. Like e.g. in the gtalk app. I'm not sure what's the best way to implement this:

  • Should I use one Activity per chat? If yes, how do I select the correct activity instance for switching to the next chat?
  • Should I use only one Activity instance and several views and switch between them like in this example?
  • Or should I use Fragments and switch between them? Does the FragmentManager provide a way to pick the right Fragment instance for switching between them?

What do you think is the best solution, and why? Any suggestions? Thanks for your help!


I would suggest taking a look at the following Android Dev blog post about using ViewPager in the Android Compatibility Package to implement the swipe functionality you're looking for:

http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html

The recommended approach is most likely to use a Fragment for the chat history and text input field as this will give you the most flexibility across devices.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号