Change content of view on swipe - android

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

Related

Android swipeable text view

I am trying to create a app where you would get a list of strings and you are able to swipe through them. What I had in mind is to have a text view and every time you swipe the text is changed to the next element in the list.
But I am under the impression that this might not be the best way to do things. Is there any other way I could do this ?

Array Adapter for an AdapterView that only shows data one way, (Android)

I get data from my server returned as an array of objects. Each object is itself an array of strings that describe the object.
For example let's use cars as the object. In this case, the array of strings are descriptors like 'year built', 'horsepower', 'automatic or manual', 'color', etc etc.
What I'd like to do is display only 1 car at a time for the user. The user can choose whether he likes or dislikes the car. Either way, a choice is final, and the next car will show up. Also, the user should not be able to go back to the previous car (not with a swipe or a clicking of aback button). In other words, he can never see his choice on the previous car again.
If I make a call to my server on every single 'like/dislike', this will be a very slow app. If I inflate a bunch of data into many views that are out of sight, it will also be a very slow app.
Most Array Adapter examples I see online illustrate how to show data bi-directionally. They are viewpagers or listviews that you can swipe left (or up) to view data that has been previously already viewed. This is not what I'm looking for.
Is there a proper way to implement what I'm trying to do? Any help will be appreciated as I'm just hoping to get some direction and can implement on my own. So far I'm thinking about possibly a viewpager that deletes items as you view them, but I have a feeling this will be really hard to manage the position of the views...
Use an array to hold the data you get from the server. You can request that the server send you 10 or 25 or 50 at a time.
Since you only want to show the user 1 at a time, and he can't scroll or swipe through the list, you only need a single set of views (enough to show all attributes of a single entry). You don't need an array adpater for this. Whenever you step from one entry to the next you just need to adjust the index into your array and then copy all the attributes of the new item into the individual views with setText() or setImageBitmap() or whatever.

Which is the better method in Android for creating a dynamic list?

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...

Read, display and update Android table values?

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.

Android store listview views into ArrayList

I have the problem of the ListView re-rendering and changing the values within my list view views. Each cell has interactive elements with numerical values that are set, unfortunately once off screen these numbers are re-rendered seemingly at random!
I've since discovered that Listview needs to have an extended view class that allows the values at that position to be stored.
I need to pass several values, so far all the examples I have seen only show one method with one values per cell (referring to http://commonsware.com/Android/excerpt.pdf), I am seeking assistance on how to store the values for my application.
I have a "total" count , and a separate count that I can increase and decrease the value of, via buttons within the listview cell. I need to store these individual totals and values within that position in the View. I supposed I would have a method/constructor that simply includes those values, but in this syntax is seems the super. will not allow this override.
Insight Appreciated. If this wasn't clear without code, sure just let me know. But if you are already familiar with this problem and the most generic way to tackle it, that would be great too.
Listview recycles its views, so if you don't store the values you are displaying explicitly using a custom adapter fit for your purposes, that is probably were it goes wrong. Whenever you scroll a view in the listview out of the screen, it throws away all the values in there, and pastes it on top with new data.
So what you probably need is a custom adapter storing the numbers you want to display; here is a good place to start off from in understanding it better: http://developer.android.com/videos/index.html#v=wDBM6wVEO70

Categories

Resources