How to do list box in android - android

am trying to do .when i click a button opens another activity and shows list box. In that list box display a list of values of particular column of table. that is we have to retrieve from
sqlite database.
how to do??
like this:
http://www.google.co.in/imgres?imgurl=http%3A%2F%2Fwww.tutorialspoint.com%2Fimages%2Ftk-combobox.jpg&imgrefurl=http%3A%2F%2Fwww.tutorialspoint.com%2Fruby%2Fruby_tk_combobox.htm&docid=SVhMpjb5FMImxM&tbnid=l4yuDUmNF-lm5M&w=220&h=242&ei=HBNRUay8B8OUrgeA94CYDw&ved=0CAcQxiAwBQ&iact=ricl

Fetch the results from database
Put it in a adapter
Populate android spinner with the adapter
Use the link below for reference
http://developer.android.com/guide/topics/ui/controls/spinner.html

Answer is to big so don't possible entire code i am just giving you guide line.
Step:
You have to fetch all record in database and store into Collection class variable.
Set those variable to adapter.
You have to used onClick and get information which is require.
You can refer this tutorial may be helpful.If this is helpful then accept answer.

Related

how to display the sorted list in listview after user presses the sort button?

I am making an Simple Android App to test the sorting capability and then use it on my main project that I will be making.
I want to know that suppose I display a list of items to the user with the help of custom objects and custom ArrayAdapter in the listview and there I want to place a sorting button that will sort the list during runtime according to the choice of the user (ex: alphabetically, according to ratings,etc.).
How to display the new list to the user after sorting.
Should I again use the setAdapter method or is there any other way?
When you click Sort Button , perfom sorting on the list , and in the next line write
yourAdapter.notifyDatasetChanged();
it will update your list with the updated(sorted) Data.
First of all, sort your source data base on the choice of the user (ex: alphabetically, according to ratings,etc.)
Ex:
List<String> mData; // your source data
// sort your data ascending order
Collections.sort(mData);
// use your adapter to update your ListView
mArrayAdapter.notifyDataSetChanged();
If you call notifyDatasetChanged() in your adapter your list will be redrawn in the right order in the screen. :) So after you order you list, call adapter.notifyDatasetChanged()

how to use a list item to call and display a string in another fragment

i am a novice in android and i was trying to make an application that has two fragments, one with a listView with topics which when one is clicked it opens a topic description in the other fragment. i would like to know how to also store the large string for the description
If the data is dynamic you can store your topics and desciptions in a sqlite database. You have several possibilities:
You load the topic and description at the start and give over the description with a method or an interface to the second fragment.
You store the data in a database and give every entry a unique id and use a method or an interface to communicate with the second fragment and put the id to it. And then you use the id to get the description from database.
UPDATE #1
You can use arrays in your resource files. Create two arrays. One with your topics and the other with your descriptions. But the topics and descriptions have to be in the same order. For example the description of the second topic have to be on the second position in its array. Now you use the first array for your listview and the second(with the descriptions) in the description fragment. The "setOnItemClickListener" method of the listview have the position as a parameter. This is the same as the position of the topics and desciption in your arrays (when you dont resort anything).

Android: Storing and showing strings in ListView

I need to have a DialogFragment or similar with a ListView which contains a list of strings. I also need to have some kind of footer or something so I can add more strings to the ListView.
Basically it is a dialog where a user can specify and add endpoints to the app, and clicking on a String of the ListView would make the app connect to that endpoint.
How could I do this? Should I use a ListView with a footer? How could I store the strings in the device?
Thanks a lot in advance!
If you want to store Strings after close your app, you should use SQLite database, there you've got a nice example of use it
SQLite tutorial,
and there you could read how create a DialogFragment with ListView
DialogFragment with ListView.
To put data from database to ListView you should get List<String> someData from your database.
To add new String you could add it to database and refresh all Dialog View, or add it to list using comand someData.add(String string);
Hope I help

Android: different objects in one list

I am a new to android developing. I am developing an android app for a shopping mall...
i want to have a screen where a list is displayed. Name of the mall and its photo should be displayed in the first section with its short one line address...
In the next sections the products should be displayed in the same way....
Product photo, Product Name and its price...
Please suggest me what topics should i read to create such a screen....
could fragments be used to create this screen???
Thanks in advance...
There are many ways. Like you can create a Customized List view for each screen. You can first create an Array List of objects of MallClassPojo. Like:
ArrayList<MallClassPojo> mallList.
Where your MallClassPojo contains the getter setter methods for Mall name,Mall image url or resourceID and short description of mall. Pass this mallList to your adapter class. Retrieve the details and show them in your customised List View. The next screen can be prepared in the same way also.
Well then you can create an Array List of JSON objects. In a JSON Object you can add different data like in one object you can add the company data and in another you can add product data. Isn't it?

logical problem in an android app

hi i would like to know solution for such a problem..... i have an xml file containing users data of around 1000 users listed out in alphabetical order. The xml file use to be as follow
<usersdata>
<user>
<id>1</id>
<firstname>A</firstname>
<middlename>AA</middlename>
......
......
</user>
<user>
<id>2</id>
<firstname>B</firstname>
<middlename>BB</middlename>
......
......
</user>
........
........
</usersdata>
Now from the above xml file i am parsing all the tags and storing them in an array list for each tag. I am listing out the Firstname in a listview, by array list of first name. When the any of the list is clicked, it opens up a new activity where the all other details of the selected name is been shown.
For example if third name in the list is clicked, by using its position(example 3), in the next activity i am listing out the third values stored in all the array lists i am using. This is what currently i am doing.
Now the problem is i have a edit box above the list view, named as a search box. If the letter S is typed in it, then all the names starting with S gets listed first. Opening the next activity by clicking the list now gets some wrong data, how to avoid this.
Please give me a suggestion....
For example if the first name C is clicked, it will be listed at position 3
There is a quick and dirty hack: you can store user id in the invisible field, retrieve it on click and use it as an argument for the second activity. I'm afraid I can't come up with better suggestions without seeing the code.
i tried out by setting some flag and by using an example code in developers site. And i am able to list out the data's but this idea does not full fill my apps requirement in the next activity. So i removed the search part in my app.
Sorry for posting such a question here......

Categories

Resources