i am currently creating an Android App in which I have data reading from a database. The main part though is that i am using the Spinner widget. As yous know, with an Android Spinner you can have as many options as you like within it.
What i want my Spinner to do is when i select an option, i would like to press a button (a Confirm or 'Ok' button) which will then navigate me to a page, which is related to that button.
For example, I'm doing sports events. So in one of my spinners, i wish it to have a list of events, and when i select a specific event, I want to be directed to a page that has content related to that event
Is this even possible? Or am i better off using a different widget?
You can use a ItemSelectedListener and in the onItemSelected method you can write your navigation code to move to corresponding activity. You can retreive the item details using position parameter in OnIntemSelected method.
Related
I'm using Recyclerview to show a list. I want to delete some items like IOS. In my listview template I have added a button to delete item which is invisible by default. In my activity I have another button attached at bottom (Not part of listview) and on tap of this button I want to make all delete buttons of listview visible.
My Question is how can I get reference to all delete buttons of listview in activity and is it the right way to do this?
Thanks
Assuming you have ViewHolders set up, you already have references to all the buttons in your list. All you have to do is to make them visible for every item in the list with a simple loop.
In case you haven't implemented ViewHolders I suggest you check out the documentation and take a look at some simple tutorials on how to use them.
On a side note. If I understood correctly you're making a bottom tab for your app and since you referenced iOS I gotta say this; Remember that Android and iOS are two unique operating systems with their own ways of handling things. Check out Googles pure Android documentation.
In your question title you say RecyclerView, but in your text you say ListView. The solution is similar either way, but it's best to be perfectly clear what you're doing.
In either case, there are at least two different solutions.
First, you could use a boolean flag to determine if all the the item buttons should be showing or not. You check this flag at the time the item view is inflated or created and toggle the button accordingly. If the boolean flag is ever changed, the easiest thing to do is tell the RecyclerView/ListView that the underlying data has changed and to redraw all the views. Call notifyDatasetChanged on the adapter.
The other thing you can do at the time the item buttons should change is iterate all the visible item views, find the button, and change its visibility. With RecyclerView, you can do this, and with ListView you can do this.
I'm creating a local android application and am trying the following:
The main menu consists of 4 buttons, each will lead to a (different) list of chapters.
The layout of the chapters view is the same, so I am trying to use one layout for every chapters page, by using different strings depending on the button that's being pressed at the main menu. So when the user presses button 1, the list of chapters differs from when the user presses button 2, etc.
I have tried looking up solutions, but was unable to find any so far. Is there a way to call a certain set of strings depending on the button that is chosen?
Have you tried to use a custom list adapter which take your array of strings as a parameter? Your list of chapter is just a simple listview with one string in each row right?
Basically, I have an app where you click a button, it brings you to another activity where you type in something and click another button, then brings you back to the first activity and whatever you wrote in the second activity is added to the first activity's arrayList, whose values are shown in a ListView. In that listView I would like to add a button to each row. How to do that?
Here is a tutorial on what you want: Handling Button clicks in a ListView Row
(Remember vague questions receive vague answers because there are many different ways to do you want and we cannot guess which particular method you are using. Always include: what you are trying to do, what you have tried (with relevant code), and why it doesn't work (with the LogCat when applicable) in your question.)
i need some suggestions first,
My application is like, on main screen a user clicks the image button "Courses" and navigates to a list, with three items, when user touches any item, he moves into another "List view" that pick up values from the database, and then if a user clicks on any item of second list,will be navigated to final view or a webview..
suggestion i need is, is it a nice practice to navigate a user from list to another list, in a
application..
and in Iphone application they make back button to each view,(as they dont have a back button on iphone) but in many android applications i didn;t seen back button in list view layout, do i need to have a back button on the top of the list view ?
Second question i have is, do i really have to make a Database for a list,
i have to make atleast 6 or 7 Lists in my application, with some list having values nearly 16
Ad. 1: No, you don't need back button in list view. It's real back button in all android devices.
Ad. 2: No. But when data are changing or you want to perform complex queries then database is preferred. In case of not changable data use xml. In case of simple data you can even use shared preferences.
Here is short guide to android data storage:
http://developer.android.com/guide/topics/data/data-storage.html
Here is simple tutorial to use hardcoded data with listview:
http://developer.android.com/resources/tutorials/views/hello-listview.html
I have a few comments on these:
1) The application might end up having a complex navigation to achieve simple tasks if there are multiple levels of lists. Consider using a Tab layout instead of the first level list, since you mentioned there are only 3 entries in the first list. Also try to consolidate your menus so that user can view options upfront
2) Back button: IMHO in android you should only implement it iff you want to override the default behaviour of the back button.
3) Database for a list: Totally depends on whether you want to change the lists once the app is installed. If they are static then you dont need to build it from the database
i am writing a software that i have to drill down on content a lot. For example when the program starts a listview is displayed. When user clicks on an item, then a second listview must be displayed. For example:
Select Continent > Select Country > Select State > Select City > Select Address
What is the best way to do this (less memory, faster, easier to code etc)? To create multiple listviews with multiple adapters? Or 1 listview with multiple Adapters? Lists are loaded from an external XML File.
So far i am creating a new adapter and setting it to the listview. How do i create a second listview and after clicking on 1st listview displaying the second one, with animation. Any examples?
Extend my class to ListActivity or Activity?
I would make multiple Activities for this. The first activity to display Continent list, the second the Country list, Third State list, etc...
When the user than click the back button. It will go back to the previous activity (list). Even the scrollstate would be remembered.
This will also add the OS animation between the activities. The code will also be separated and memory freed when closing the list activity.
Sending a value from one activity to another ex CountryCode tot the StateListActivty is done by setting a intent.putExtra("CountryCode", countryCode);
A second approach would be to use a ViewFlipper. Adding each listview as a child. And than setting a custom animation on the show-next and show-previous actions.
Note: Using multiple activities may use abit more memory than the ViewFlipper approach.
I would use separate activities for each list but with only one List Adapter class to be shared by all so you can retain consistency in terms of how the lists look + easy to maintain code. You can use a bundle to pass info from one activity to another.
Another thought: is the info you are referring to part of "settings" info? By that, I mean, is it info the user would put in once into your app, or would they put it in almost everytime they use the app (because each time the info would be different)? If it's an "one-off" type of info, you would be better off using a PreferenceActivity.