I'm new to android, I spent the last 2 days trying the previous examples and online solutions, but I just can't think about it :(
I can display the list view, parse json from the Internet and save the book title, book description and book ID and display this data in the list. I want the “download” button to be entered on each row for the ListView, each button will correspond to its book ID in Click (), and the action listener will load the book by adding that ID to the URL. e.g. www.books.com/download_book1 or / download _book2 ....
Here is my code. Class Catalog.java
public class Catalogue extends ListActivity {
private JSONObject json;
private ListView lv;
private ArrayList<Integer> alKey = new ArrayList<Integer>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shelflist);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
....
try{
JSONArray entries = json.getJSONArray("entries");
for(int i=0;i<entries.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = entries.getJSONObject(i);
alKey.add(e.getInt("key"));
map.put("id", String.valueOf(i));
map.put("title", "Title:" + e.getString("title"));
map.put("description", "Description: " + e.getString("description"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.shelfrow,
new String[] { "title", "description" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
lv = getListView();
lv.setTextFilterEnabled(true);
.....
. , 1 .
shelfrow.xml(textView, textView item_title item_subtitle) shelflist.xml(ListView).
shelf.xml