create android cards with fragments - android

I am new to android and I am working on a project that contains something similar to a news feed. My plan is to get information from a database display it on a card. I just discovered fragments and thought they would be a great way to do this. My question is can I design a fragment as a default card and change info on the general card to the info I get from the database and add the card on to the screen while the app is running?

Yes you can.
Fragment is a lightweight activity, it's held and hosted by activity and manage it's own UI and interaction. According to your description, the card seems very simple, so my suggestion is using a View.

Related

How to make a layout which has some questions and some radio buttons for it and we have to swipe it

Basically I am saying that I want to make an quiz app which have some questions and some options with radio buttons so what I want is that every questions appears and after that when I swipe the screen next question comes and when I swipe back previous question come and how to store questions and basic structure of how to make an app like this
I have created something very similar in our business app. My solution was (as we used server to "generate" question) to build each question from components. Each component is of a type (let's say title, radio buttons, input field) and then I built each question using a LinearLayout. Adding components in a vertical LinearLayout as I got them from server in a JSON list. You just have to define data you will receive.
About the first part, how to show those questions. My solution was to create a ViewPager of custom Fragments. I used one Fragment per question which is able to render a question of a given data and manage user interactions. If you want to show user previous and next quesion you can use negative margin on ViewPager. You can find some documentation on CommonsWare's blog.
If you define questions in a similar way as we did, and want to store them locally you can store them as a JSON in SharedPreference or you can use database for that. Probably SharedPreferences will be the easiest option for you. You don't really have to use JSON, you can use any type of format you can read/write.
Have you tried a Google search?
There are tons of tutorials out there to help you get started. Grab something simple to get started with and then add the features you need.
Swiping back and forth is done with a View Pager
You can store the questions and answers with Shared Preferences
Good Luck

How to open page with result like contactbook?

In my UWP-App I want to create an app internal contactbook page. I can select a contact and return the selected contact back to the page where I opened the contactbook.
In Android where I come from there is a function called "startActivityForResult" which opens an activity gets the return value when finished.
I want to create the same behaviour.
I did this with Frame.Navigate(typeof(ContactBook)) and then when the contact is selected I navigate back with Frame.Navigate(typeof(PreviousPage), selectedContact)
The method Frame.GoBack() is useless in this case because I can't pass a parameter.
How can I solve this problem?
I'm not 100% familiar with android and "startActivityForResult" but are you looking to navigate the entire frame away? There isn't any equivalent in UWP apps, nor is there even really one for WPF's showDialog(), which is probably what you're looking for.
You only have a few options and none of them are really "amazing" per-say.
You can do what you've done above, which is navigate away to the page that has all the contacts, then navigate to a new page but depending on how your app is layed out you might be losing data on the page (since it's a new instance and not a back in the stack so you can't really cache it). You also can't navigate to an instance of a page either, it's only to a new page or through the stack from back / forward. If you use GoBack though and cache the page (using the "required" mode for caching) then you could do some dirty lookup of a stored value in a static class (I know, ugly and not MVVM) or setting a local settings value and reading that in the OnNavigatedTo() method for the page before.
If you don't NEED to use frame movement, you can use a flyout or a custom flyout user control to build a popup of sorts that will display the XAML for the page instead of a page frame. This will have a few difficulties with resizing (so more so for W10 than W10M) and such but you'll be able to not transition out of the frame itself. Then you can see the value of the selected and then on the submit event, you can just work with the page since it's already open.
If need be you could build a custom usercontrol for the flyout and put some custom dependency properties that can be bound for MVVM, it really all depends on what and how you're doing it.
So short answer, there is no fast way of achieveing what you're looking for and that does seem like an issue with the API. I would make the suggestion on the API's uservoice (https://wpdev.uservoice.com/forums/110705-universal-windows-platform) and try to get it upvoted!
There isn't any equivalent in UWP apps, nor is there even really one for WPF's showDialog(), which is probably what you're looking for.
#Daniel, no, there is a equivalent in UWP apps. Please refer to Launch an app for results, you can follow the tutorial in that doc to achieve this.
To do this, you will need to create two apps. One is the app which will launch the result app (let say "main app"), the other app here should be the contact-book app. The contact-book app will behavior like a modal window, and the main app will wait for the result of the contact-book app.
But in an UWP app, you can use ContactStore class to access the database that contains contacts.
So, you will need to reconsider if that is necessary to create a contact app by yourself.
Edit:
I may misunderstand your question, you just want your page to behavior like contact-book, not want to create a contact-book by yourself. But anyway, it's the same, you can create another app to hold your page which you want to launch from your main app.

Architecture of Android app to display data from WS

I want to build an Android app to display a list of different music singers with some data on each row and a small photo of album. Should be small navigation after selecting an artist, you can go to his albums and then to his songs...
1 - what would be the best architecture design for this kind of app? I tough about implementing it in this way:
When splash screen appears I call to a web service to download the information and save it on device DB.Then I use Loaders to load all this data from DB, after load is complete I remove the splash screen and display the list. For each item click I bring the data from WS and display it. my question is do I need to involve actually DB for this? and is it good to fetch data for each item selected (singer), if I go back and then press again the same item, do I have to bring again all the data from WS?
2 - Anybody can recommend site where I can learn about architecture of apps, not the linux-android architecture but real apps.
Ok I'm not sure if it's the best approach, but give this blogpost a try. It helped me a lot, because it gives you kind of a convention how to design android applications (I'm coming from rails^^).
http://blog.joanzapata.com/robust-architecture-for-an-android-app/

Android - Reading data from tabs / fragments

I'm working on an Android app that does nothing more then storing data in a SQLite database and displaying it.
Since I have a .NET background I started off developing the app with MonoDroid (C#). After developing the app with MonoDroid I thought it would be fun to redevelop it with Java and learn along the way.
In the original app I used a TabActivity and created 4 tabs to stucturize the data I want to save in a single table. Underneath the tabs I placed a button. A click on the button collects all data on the 4 tabs to store it, and it worked perfect.
Now developing with Java I noticed that the TabActivity is deprecated and I found out that I have to use fragments. I was able to create the tabs following this article. However, I am no longer able to read the data on the tabs. I searched online and tried the most ridiculous "solutions" for a couple days in a row now, and I start to doubt if the functionality I look for is possible.
Please advise me what to do! Is it possible to recreate this functionality using fragments? If so, can anyone give me some pointers?
If not, what would be the best way to approach this?
Thanks in advance!

Convert existing app to use Fragments

I am new to Android and have an app on the Market that I would like to convert to use Fragments so it could take advantage of the tablet in landscape mode and have both activities side by side. All of the examples I can find out there use a listview with a image or text in the right column and uses the FragmentList class. My app has an Activity that has buttons and depending on what buttons or spinners they select it then displays another activity. Can anyone recommend a tutorial or article on how to do this? I have read the Google blog but found it confusing and wasn't sure how to use it to modify my existing code. Any help would be appreciated.
This is a good tutorial http://portabledroid.wordpress.com/2011/04/19/programmatic-and-layout-fragments/

Categories

Resources