Intent With Listview (json Data)
Solution 1:
I suggest you rewrite your SimpleAdapter to extends ArrayAdapter<News>. Creating another List of HasMaps is quite useless and consumes additional memory. Than make your News class implement Parcelable. And in onClick() you call something like:
publicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
Newsnews= parent.getItem(position);
if (news != null) {
Intentintent=newIntent(...);
intent.put("news", news);
startActivity(intent);
}
}
Solution 2:
Always use a non-UI thread to fetch data from servers. Looking at your code it looks like you are using the UI thread to fetch data. You may use AsyncTask and paste the code written in the GetJson class in the doInBackground method of an AsyncTask object.
Now about your problem to pass the clicked list item data to the next activity. You will have to either make the class News implement Parcelable or Serializable interface. implementing these classes allows you to send the custom object data to another activity. The most efficient way is to implement Parcelable.
Check the following links for more details: http://developer.android.com/reference/android/os/Parcelable.html
http://developer.android.com/reference/java/io/Serializable.html
Hope this explanation helps.
Post a Comment for "Intent With Listview (json Data)"