I want to create a clickable items from a scrollview or listview where items came from a JSON which is fetched from my online database. Now I don’t even have an idea on how to work with this one since I don’t know how to dynamically create an object through codes to insert the database items. Well the concept is simple I just need to display a list through codes then assign an ID per row, click one of the row then move to a new intent where details are displayed matched by ID assigned on the selected row. Can anyone give me an example or links on how can I work with this one?
Share
You need to study ArrayAdapter and JSONParsing, there are many tutorials for that, I will try to explain these in a brief:
An AdapterView is the view, which items/childs are determined by some adapter. Like ListView, Spinner.
An Adapter is a bridge between AdapterView and underlying data.
See ArrayAdapter as it seems best according to your requirements.
To Understand JSONParsing, you need to understand JSONObject, and JSONArray:
A JsonObject is a key: value pair, where key need to be string and value might be a number, a boolean value, or some other datatype, or JSONOjbect, or A JSONArray. and its represented by {}. like {“key”:”value”, “key1″:”value1”, …..}
A JSONArray is an array of values, values might be a number, a boolean value, or some other datatype, or JSONOjbect, or A JSONArray, and it is represented by []. for example: [“value1”, “value2″….]
There is no need to set item view’s Id, because you can find which item is being clicked, by:
http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html, method
onItemClick(AdapterView parent, View view, int position, long id), you would have position of item being clicked. But If you still want to assign an id to item view, then do it in getView method of Adapter. by View.setId() method.