Architecture of activity / fragments for search bar - android

I have a project in which on main screen I show a list of items . (An activity and a fragment that contains the list )
In title bar I want to add a search functionality with autocompletetextview .
Now in title bar there are the title and "search" button . When the search will be clicked the title will be gone and autocomplete visible .
I would like to follow the functionality that is now in common apps : messages , gmail etc but I can t figure what it is the best solution regarding architecture of fragments/activity components to implement .
1, When I clicks the search button to show another fragment ?
2. When I click search button , title change visibility to gone and it will be used the same fragment with items and it will be updated ?

try with a simple MVP, organizing the view in a passive view(less data as possible). I have the feeling you are not practical of architecture if you ask, because looks as a simple question. MVP is in my personal opinion the best way to start.
you can test your app View using Espresso, and the business logic into the presenter with Junit.
From the project indicated on the first link, you can easy clone the project and see an App that is quite similar to the one you use( on click opens a new activity, activities/fragment) plus much more.

Related

Android - How to have multiple pages/section in a fragment? (No viewPager)

For better Understanding check this sample design
What I want to achieve is a sign up mechanism. Where when a user done filling page 1 and click next then
The next button stays at the fixed location
The indicator do an animation and change
The two field ("Full Name" and "Select your gender") get swapped out by the fields of Page 2.
Those fields in both pages will be in same Fragment, viewModel and repository. This is a simplified version of what I want to achieve.
I am a beginner in Android & already watched tutorials of viewPager2 but I'm pretty sure it won't help here. One thing I can do is, to use "visibility hide & show" but I don't think it would be the best practice. Hiding and showing will also not help in manually swapping the pages.
So, how to implement multiple pages/section in a single fragment?

Change activity content dynamically based on users option click in android

I have implemented below tree structure options in navigation, whenever user selects any option, I want activity content to change. Now the main challenge here is Activity content could be too big and It can include many types of fields like links, images, normal text. My purpose here is whenever user selects any option, activity will show that option related information. Now for the first option, it can have multiple images to show, text and links, second option click may not have links but it can have images, information text. Its more like XML structure will change dynamically based on user choice.
Navigation view with activity
I am new in android and I want efficient method to implement such functionality.
Below are the methods which I can think of
For each option click show new activity : I can't implement this because I would have to implement this navigation option code in each activity which is too complicated for me (if anyone has any better idea to implement this approach then please let me know)
Change XML content of activity dynamically : Can I do something like for each content I will write XML pages/file and change it dynamically, I would like to know how to implement this method.

How to design an android activity in order to view recent posts with the support of "see more" property like facebook?

I want to develop an android application in order to facilitate the communication between students in some college through sharing posts and subjects written by them, so my idea is to create an activity showing recent posts.
i think that i need listview widget to show posts in a way such that each item in this listview will show one post with its title. is that correct? please, i want just the names of widgets which may used in such activity, and how to support "see more" for each post like facebook?
thanks
For see more you can use Floating action button. If new posts are available and the use scrolls down then the floating action button become visible.

Android Search View Filter

I have an Android app with a Main Menu filled with buttons. In the Action bar corresponding to this view I have a Search Button configured to use with the Search View widget.
For this to work I have another class that is the searchable one that makes the hard work and has a List View with all the products that my database has.
What I'd like to do, and I don't know how, is that when the user is in the Main Menu and presses the search button, nothing changes until it introduces some letter. When he does, it should start show the filtered products list, just like WhatsApp app does with the contacts and conversations. This should be done "on top" of the buttons that my Main Menu already has, because if I change to another Activity then the Search view widget will close.
What am I thinking wrong here?
Check this code out:
https://github.com/commonsguy/cw-omnibus/tree/master/ActionBar/SearchView
If I understand you, this is what you do currently:
https://github.com/commonsguy/cw-omnibus/tree/master/Search/Lorem
He does "Query-style search" but you can also do "Filter-style search" mentioned at page 2521 in the book from Marc Murphy. But this is not described. So far I'm using the first github example.
This is also a nice example that expand on Lorem with automatic suggestions. Only work for Activity and not Fragment (also found in SDK samples/android-14):
https://github.com/android/platform_development/tree/master/samples/SearchableDictionary

switch to a new activity, instead of switching fragments, when jfeinstein10's slidingmenu list item is clicked

I have seen a few questions raised on this topic (for e.g.: https://github.com/jfeinstein10/SlidingMenu/issues/5) but I am still unclear. I hope somebody can clarify this.
Context:
See https://github.com/jfeinstein10/SlidingMenu
I have an android app that organizes screens by activities and fragments (i.e.) each screen is an activity containing one or more fragments.
The new requirement is to add a sliding menu (similar to what this library provides).
Issue:
It appears from the examples and discussion that the right model would be to have just 1 MAIN ACTIVITY that will then switch in/out fragments belonging to the different screens. In fact the author mentions in the above thread: "If you were to launch Activities based upon the list selection, then you would not have the behavior where you swap the views that you're talking about. " and also "You can't put an Activity into the above view. That doesn't really make sense when you think about what an Activity is. ".
Why doesn't it make sense? Obviously, I am missing the point here.
Question:
Given that my project already contains multiple activities (one corresponding to each screen), is my only option then to re-organize the project to have JUST 1 MAIN ACTIVITY, in order to use this library? Or alternatively, is there any way to launch a new activity when a list item in the sliding menu is clicked, and still observe the sliding menu behavior, [EDIT- added the last part to be more clear] or in other words, on how exactly to use this library within my existing app design.
Thanks in advance
First, you can't have an Activity inside another and activities are completely different from views as stated in the docs:
An activity is a single, focused thing that the user can do.
Now, to answer your question, it all depends on how you want your app to behave. You could have your activities with the sliding menu implement the onClosedListener and switch to the selected activity from there. This will give you the animation of closing the menu before switching activities. It will also give you a weird effect since every time you select something from your menu you'll see the animation of a new activity coming to the front.
I think the best approach would be to have a "common purpose" between all your sliding menu options. For example, in one of my projects I have to allow the users to select between lists of different types of data. When the user selects anything from the menu, I load a new list fragment into the right corner where he may choose the item he wants to view or edit. That's the app entry point and also the only place were I have a sliding menu in my app. It is pretty much the same for every app that implements this UI design pattern. Look at google+, currents and youtube where the side menu lets you choose which feed or content to show. Once a user makes a selection, just open a new activity for the selected item (a g+ post, a video, a news article, a tweet or whatever it is).
Your app doesn't have to have lists of different data or anything like that to use the sliding menu, but keep in mind that the activity with the sliding menu should have a clear, focused goal with respect to its functionality and purpose. Having a sliding menu because many other apps have one is a bad choice, you should use it with a specific objective. Also keep in mind that applying the sliding menu everywhere would interfere with the platform's navigation pattern and lead to an overall bad user experience since it wouldn't behave as the other apps.
It doesn't make sense to place an Activity into the above view because the Activity is the main controller for the view of each screen. The Activity also shows views and keeps track of Fragments (which in turn are mini controllers, with or without their own views). So placing an Activity in the above view would mean that you would place an Activity in an Activity... Wich is impossible.
From what I can derive from your text I think it would be wise to read through the Android developer guide on Activities and Fragment again (http://developer.android.com/guide/components/activities.html) to get a better understanding of how the concept of Android works.
Now to your question:
I am not clear on what you are trying to achieve but if you want your app, with menu to behave like, say, the Google+ app then one way of doing it is to implement a base class that extends the Activity class (or what ever base Activity used in your project) and let the base set the SlidingMenu. Then you would simple extend your base Activity in each of the Activities that are supposed to have a menu.
You could also do it the way you describe it, but then you would end up with a classic example of a God object (http://en.wikipedia.org/wiki/God_object). It's a neat way to practice your Fragment juggling skills and switching between Fragments instead of starting new Activities does have it's use cases, but I still wouldn't recommend it for a project with more then a few views.
Here is the answer that came closest to the issue I had - http://www.verious.com/article/polishing-the-sliding-app-menu/. Scroll down to the bottom of the page to see the last section titled "Using the fly-in app menu between Activities". This is one option if you have a lot of activities in your existing app and want to avoid extensive re-factoring. I haven't tried this out yet but its worth being aware of.

Categories

Resources