Android Dynamic GridView updates within seconds - android

I want to create a dashboard wherein I want to populate some data in a GridView in android. For example,
Activity - GridView in which there are two columns.
Each grid is Header Text and Result Text.
Now I want to update only Result Text with time as I am fetching it from database and updating the values in real time.
Keeping my Header and whole view intact.
Can anyone suggest any quick way to do so...??

You only need to update the underlying data of the adapter and call notifyDataSetChanged() so the adapter knows the data was changed.

Related

change date difference when application loads

So im using a SimpleCursor Adapter to load up my task list, and in each row there is a text view with the time left in it. What i want to do is update the list rows when the user goes to the listview activity so it will update the time left. the problem im having is simple cursor adapters fill the list with items from the database and i need to change the time left text via android by calculating it on the fly and only accessing the DB for the datedue.
I tried storing the timeleft into the DB then updating it when the list is shown but thats not working and seems pretty messy.
edit: I do know how to calculate the time difference. All i want to know is how can i fill a list with Cursor items and non-cursor items.

How do I show Paging in a dynamic tablelayout?

In my application I am getting data from server and showing it using a table layout some times I am getting a data of atleast 20 to 30 rows but I want to show 4 rows at a time and then I want to show another 4 etc.
For this I want to know how can we use paging (Previous/Next) in Android if it's not possible with tablelayout can any one suggest which field can give that facility I aleady tried with GridView also but no luck
You can try this way ...
Store parsed data in List(or whatever) and create a method say createRows() which takes list as its argument and using list create rows.
So from your main list (parsed data list) create a sublist of size 4 and pass it to method. So initially it will create table with 4 row (as your requirement).
And on your next button first remove table's current rows using removeAllViews() method and then extract another sublist containing next 4 data to be shown & again pass it to createRows() method.So now it will create table with new data.
Same thing can be applied to previous button.
you can do it with fragments, there will be two fragments one will contain buttons(prev/next) or other fixed position data. and the other fragment will dynamically load data on request of button if you can program it.

What's the best way to handle a list view whose cursor gets frequent reads and writes?

I am building an Inventory application. The items are shown in a grid view and each cell of the grid view also has a TextView in the upper right corner that displays the available quantity of the item. The user can single click on the gridview cell to increase the quantity or long click to decrease it.
I am currently using a class derived from SimpleCursorAdapter to display the data, but I am not sure about how to update the quantity in the DB. I am afraid that if I write directly to the DB and then create a new cursor and change cursor that the application might become bogged down if the user clicks repeatedly (say to add 10 items)
I have considered copying the data from the query cursor to an array in the Activity and then using an ArrayAdapter but this seems kludgy.
I have also thought about creating an array in my SimpleCursorAdapter which would cache items that have been modified and then save those items when pausing...
Is there a better way? A more Android way?
I guess this comes down to: what is the best way to make rapid changes in the DB and UI?
I don't know much about Cursors in this regard, but I would create a custom ArrayAdapter based on a model object rather than a Cursor. That's just a personal preference, but by doing this I don't have to make any assumptions about the Cursor implementation or know it inside and out.
Let's say you're displaying a collection of type Item in your grid. I would create a class called ItemsList that derives from ArrayList<Item> and my adapter would derive from ArrayAdapter<Item>. The reason you create a wrapper around the ArrayList is that you can allow the user to interact with it freely and mark it as "dirty" and allow it to update the database asynchronously. This way, you just call notifyDataSetChanged() on your adapter and you don't have to think about the overhead of updating the db...you've separated interacting with the collection being displayed and the process of updating the persistent storage.
Btw...this video is a must when working with ListViews and Adapters if you haven't already seen it:
http://www.youtube.com/watch?v=wDBM6wVEO70
You could use a regular listView and a regular Adapter with a list (arraylist) of items in it. Every time user clicks or long clicks you can edit the list in your adapter and notifyDataChanged() which will reflect the list changes on your listView. If you want to keep your list after user quits your application you can use either database(for bigger amount of data) or preferences (for smaller data amount).

pagination in Listview of android using Base adapter?

i use the base adapter to fill the list view with the dat fetched from SQL lite . My actual requirement is to show only 10 row in a list view , when i click next ,the set of next 10 data from local database need to fetched and update the current list View. but i don`t know how to implement this.
anyone provide some sample code or solution to solve this issue.
Thanks
The simplest way would be to send the adapter only a subset of the entire data ( in your case 10 elements) . When the next button is pressed , you can send the adapter the next 10 set of elements and then call notifyDataSetChanged on it to update the listview.

How to make a list that can show the changeable content

I have build an application in android. This app needs to display a list of text, but the list of text increase continuously. It means user can see increased list of text. Each text is separated by a horizontal row. It looks like google market when market try to show list of applications. How can i do in this situation ?
You didn't mention where the data came from but let's suppose that you have an ArrayList of your model Text.
Steps:
Add a ListView to your layout
Extend ArrayAdapter
Set this new adapter to your ListView
Modify the array adding/removing new stuff
Notify the ListView that the data has changed using the adapter's notifyDataSetChanged() method.

Categories

Resources