This is more of a question about getting my head around the process I need to follow really.
I short:
I need to read the exisiting table (a rugby squad) and display it on screen.
The user has the option of tapping any entry and updating it - and repeating as necessary.
The user can then tap "Accept" or "Cancel"
If "Accept" is tapped I obviously want to update the table with the new values.
The squad can be from 10 to 22 players, so I need the display to be fairly dynamic and ideally I need a shirt number (static), a name (text, updateable) and a "starting" checkbox (updateable)
I've kind of got my head around each on the indiviual components, but when I try and tie them together it all goes pear-shaped!
Can anyone point me in the right direction, please?
It sounds to me like a simple datbabase backing a ListView would be the way to go. That way you can offer different options for sorting the list, etc.
EDIT
In your main xml have the listview and two buttons at the bottom (accept and cancel).
Create a Listview rowlayout.xml that contains a textview, an edittext and a checkbox.
Populate them like normal (you can use setText() on an EditText just like a TextView). Put the shirt number in the textview and the player name in the edittext and the starting state to set the checkbox.
Then you simply wire up the accept button to cycle through the list and commit any changes you made and the cancel button to reset them all to the last saved values.
Related
Hi, I have to make a listview like this image.
These letter A,B are auto scrolled by the listview.
The Letter A is appear until there is no Item start with A in the list view.
I dont have any problem with the list view in the right. My difficulty is showing letter abc along with the listview.
Can anyone help me about this?
Thanks.
I'm assuming that you already know how to make a list view to display data and/or images as the image above illustrates, and that your primary difficulty is to show the "A", "B", "C", etc.
If that is the case, then a good approach would be to specify a list of models (data), each containing a field of "name", "imageUrl" & an optional "firstLetter" which can be null.
When you sort these models by the "name" field, you go over the list once, and on each iteration you check if the 1st letter of the "name" field is different than the previous one (always true for the 1st element). If this is the case, the "firstLetter" field is set to the upper-case first letter of the "name" field. Otherwise, it will be null.
Then in your adapter, if the "firstLetter" field is not null, then make the TextView which displays this letter visible (otherwise, make it GONE), and assign the text to the value of "firstLetter".
EDIT:
The above was written before you asked for the "A", "B", etc to be "sticky" and remain until there are no more items beginning with that letter.
To implement the "sticky" behaviour, similar to the WhatsApp app which makes the dates of the texts sticky, you can create an additional view which floats over the list (you'll need to make sure that the paddings, styles and fonts match so that everything looks good).
Then, in your adapter, you'll need to check the following:
Am I already displaying this "hovering" letter for the letter that my cell wants to show? if that's the case, don't show it. This will prevent showing two "A"'s when the "A" is partially outside the screen.
Is the position of my cell which is showing the "A" or "B" slightly outside of the screen? If so, make sure to show the "hovering" letter and give it the correct text.
I think you have to use 2 listviews on a relativeLayout. First with the Capitals of the names and second, the list you want to show.
For make your listview you must create your itemList.xml, with name and photo like you want for create your listview.xml. You will need a "people.java" class with atributes, for example, name and photo. Also, you need one adapter for create the relation between your list.xml and your mainclass.java.
This page is in spanish but the code could be usable for you:
http://www.oneoctopus.es/desarrollo-android/listviews-personalizadas-en-android/
When you are getting the data in adapter class then check for each object and its first word extract their first word in a char and compare that first word with other objects if they are same ignore and if different then save the previous char to temp char and assign the new one to previous char and so on.
For the sticky letters index, you can do the following:
On the leftmost side of your RecyclerView, create a TextView that will hold the letter index;
On the top of the Recycler view (in the layout that wrappes it) place a TextView in order to cover the one you created in step 1, this will be the sticky one;
Add a OnScrollListener in your RecyclerView. On method onScrolled (), set the TextView created in step 2 for the reference text taken from firstVisibleRow. Until here you shall have a stiky index, without the effects of transition;
To add the fade in/out transition effect, develop a logic that checks if the item previous of the currentFirstVisibleItem is the last of the previous letter list, or if the secondVisibleItem is the first one of the new letter. Based on these information make the sticky index visible/invisible and the row index the opposed, adding in this last the alpha effect.
I've answered about the sticky-index in this question and also provided a library that does this behaviour. Hope someone still needs it: https://stackoverflow.com/a/30679418/2068693
If you are creating a very dynamic list, say, where every row can have a different set of input types plus optional buttons, and the list length is based on another dynamic value, is it better to do this in a list adapter or creating a custom view in a scroll window?
After struggling with list adapters for quite a while now something finally occurred to me- this seems dumb. It seems like I am going through a lot of work keeping track of what spinner is set to what value, which row was clicked and so forth.
For example, say you are showing something like a contacts screen with various details that can be entered about a contact. Some rows will have text inputs (name, address etc), some will have spinners (ie. state, group), some will have checkboxes (like 'favorite' or something). Also, there is an 'add' button that allows you to add another field to edit. Is it worth making this in a list adapter or is it better to populate a custom view, and if the "add" button is clicked, we re-create the custom view, adding a view of the type they want to add?
I hope this is clear.
ListViews (and List Adapters) are meant for data that is to be displayed in mainly similar views. For your example, it is much easier and more natural to have a predefined layout file with the screen and use view visibility so select which views are to be shown. If you need to add views to the screen you can do this dynamically by using findViewById on the layout and then using it's addView method.
Let me know if you need more clarification or sample code...
I'm making an android app that will essentially show the user a word, definition and example for each element in the database. It's sort of like a dictionary. I have already made it so that all the words, along with their definitions and examples, have been entered into the database but now I am trying to figure out a way to display them.
What I would like is to have 3 textviews which would contain the word, definition and example respectively in a view and every time the user swipes down to go to the next word entry in the database. Every time the user swipes back I'd like the view to repopulate the textviews with the previous entry in the database.
What I'm wondering is what is the best way to do this? Is this there a particular class that deals specifically with this type of thing? Bear in mind that I don't want to switch views since I would have to make over 300 views but rather just repopulate the values of the textviews with the new values from the database. Bonus points if it's easy to make a flip/slide animation with each swipe but it's not really necessary.
You can use 'onFling' method. You can detect the swipe direction and with a listener for the right direction swipe, you can call your methods for the data source.
here is an example : How to detect swipe direction between left/right and up/down
i am implemeting sample application in android for creating Dynamic Views.
Please observe below image............
By seeing the above picture i want to create a dynamic view it consists of close imageview, button, spinner and edittext by clicking Plus button. After entering all fields then i click on plus button create new view with above widgets similarly.
I want to delete particular row by clicking delete imageview. and again add by clicking plus, repeat this process untill how many rows we want. Then we click on submit button get all rows of views values and show those details on next screen....
And also tell me other way that is, Is there any possibility of create seperate xml file for that view and use it on our code...
Like see below picture...
Please help me....
Thanks in advance.....
If you Store the Views in a iterable data structure like List, you could iterate over them when a "delete"-Button is klicked and search for the ones to delete by checking the coordinates by calling getX() and getY().
However, like lfor said before, the better way would be to create an own data structure for each row. I would recommend to create a "Row"-class containing the views you want to add per row including the "delete"-Button and passing the Activity you want to add the rows to as a reference. By doing so you can add the components for each row by calling the activity's method addContentView() inside the "Row"-class. Also you know which Views (all of the "Row"-Object you're in) you have to remove, when the delete button is pressed.
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