Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to set listview text
    primarykey
    data
    text
    <p>I am using json parser to pass image url and description into my listview. now i managed to load the images but how do i change the text for my list view? currently it just shows item 0, item 1 and so on.. how do i pass the description into the lazyadapter?</p> <p>Main activity: </p> <pre><code>public class MainActivity extends Activity { // CREATING JSON PARSER OBJECT JSONParser jParser = new JSONParser(); JSONArray guide = null; ListView list; LazyAdapter adapter; String[] mImageIds; ArrayList&lt;String&gt; guideList =new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; descriptionList =new ArrayList&lt;String&gt;(); // GUIDE URL private static String url_guide = "http://58.185.41.178/magazine_android/get_guide.txt"; private static final String TAG_GUIDES = "guides"; //the parent node of my JSON private static final String TAG_DESCRIPTION = "description"; private static final String TAG_IMAGE = "image"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // LOADING Guide IN BACKGROUND THREAD new LoadGuide().execute(); list=(ListView)findViewById(R.id.list); adapter=new LazyAdapter(this,guideList); list.setAdapter(adapter); Button b=(Button)findViewById(R.id.button1); b.setOnClickListener(listener); } @Override public void onDestroy() { list.setAdapter(null); super.onDestroy(); } public OnClickListener listener=new OnClickListener(){ @Override public void onClick(View arg0) { adapter.imageLoader.clearCache(); adapter.notifyDataSetChanged(); } }; /** * Background Async Task to Load all product by making HTTP Request * */ class LoadGuide extends AsyncTask&lt;String, String, String&gt; { /** * getting All videos from url * */ protected String doInBackground(String... args) { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); // getting JSON string from URL JSONObject json = jParser.makeHttpRequest(url_guide, "GET", params); // CHECKING OF JSON RESPONSE Log.d("All guide: ", json.toString()); try { guide = json.getJSONArray(TAG_GUIDES); for (int i = 0; i &lt; guide.length(); i++) { JSONObject c = guide.getJSONObject(i); //String title = c.getString(TAG_DESCRIPTION); String image = c.getString(TAG_IMAGE); String description = c.getString(TAG_DESCRIPTION); guideList.add(image); descriptionList.add(description); System.out.println(guideList); } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // UPDATING UI FROM BACKGROUND THREAD runOnUiThread(new Runnable() { public void run() { /** * Updating parsed JSON data into ListView * */ adapter.notifyDataSetChanged(); } }); } } } </code></pre> <p>Image adapter: </p> <pre><code>public class LazyAdapter extends BaseAdapter { private Activity activity; private ArrayList&lt;String&gt; data; private static LayoutInflater inflater=null; public ImageLoader imageLoader; public LazyAdapter(Activity a, ArrayList&lt;String&gt; guideList) { activity = a; data=guideList; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader=new ImageLoader(activity.getApplicationContext()); } public int getCount() { return data.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; if(convertView==null) vi = inflater.inflate(R.layout.item, null); TextView text=(TextView)vi.findViewById(R.id.text);; ImageView image=(ImageView)vi.findViewById(R.id.image); text.setText("item "+position); imageLoader.DisplayImage(data.get(position), image); return vi; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload