Android Open Source - Android-Parsing-YQL-using-JSON-Tutorial List View Adapter






From Project

Back to project page Android-Parsing-YQL-using-JSON-Tutorial.

License

The source code is released under:

Apache License

If you think the Android project Android-Parsing-YQL-using-JSON-Tutorial listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.androidbegin.yqltutorial;
/*ww w.  j  a  v  a2  s .co m*/
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

  // Declare Variables
  Context context;
  LayoutInflater inflater;
  ArrayList<HashMap<String, String>> data;
  ImageLoader imageLoader;

  public ListViewAdapter(Context context,
      ArrayList<HashMap<String, String>> arraylist) {
    this.context = context;
    data = arraylist;
    imageLoader = new ImageLoader(context);

  }

  @Override
  public int getCount() {
    return data.size();
  }

  @Override
  public Object getItem(int position) {
    return null;
  }

  @Override
  public long getItemId(int position) {
    return 0;
  }

  public View getView(final int position, View convertView, ViewGroup parent) {
    // Declare Variables
    TextView txttitle;
    TextView txtdesc;
    ImageView thumb;

    inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View itemView = inflater.inflate(R.layout.listview_item, parent, false);
    // Get the position from the results
    HashMap<String, String> resultp = new HashMap<String, String>();
    resultp = data.get(position);

    // Locate the TextView in listview_item.xml
    txttitle = (TextView) itemView.findViewById(R.id.title);
    txtdesc = (TextView) itemView.findViewById(R.id.desc);
    // Locate the ImageView in listview_item.xml
    thumb = (ImageView) itemView.findViewById(R.id.thumb);

    // Capture position and set results to the TextViews
    txttitle.setText(resultp.get(MainActivity.TITLE));
    txtdesc.setText(resultp.get(MainActivity.DESC));

    // Capture position and set results to the ImageView
    // Passes thumbnail images URL into ImageLoader.class to download and
    // cache images
    imageLoader.DisplayImage(resultp.get(MainActivity.THUMB), thumb);

    // Capture button clicks on ListView items
    itemView.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {
        // Get the position from the results
        HashMap<String, String> resultp = new HashMap<String, String>();
        resultp = data.get(position);
        // Send single item click data to SingleItemView Class
        Intent intent = new Intent(context, SingleItemView.class);
        // Pass all data title
        intent.putExtra("title", resultp.get(MainActivity.TITLE));
        // Pass all data description
        intent.putExtra("description", resultp.get(MainActivity.DESC));
        // Pass all data thumbnail
        intent.putExtra("thumbnail", resultp.get(MainActivity.THUMB));
        // Start SingleItemView Class
        context.startActivity(intent);

      }
    });

    return itemView;
  }
}




Java Source Code List

com.androidbegin.yqltutorial.FileCache.java
com.androidbegin.yqltutorial.ImageLoader.java
com.androidbegin.yqltutorial.JSONfunctions.java
com.androidbegin.yqltutorial.ListViewAdapter.java
com.androidbegin.yqltutorial.MainActivity.java
com.androidbegin.yqltutorial.MemoryCache.java
com.androidbegin.yqltutorial.SingleItemView.java
com.androidbegin.yqltutorial.Utils.java
com.example.yqltutorial.FileCache.java
com.example.yqltutorial.ImageLoader.java
com.example.yqltutorial.JSONfunctions.java
com.example.yqltutorial.ListViewAdapter.java
com.example.yqltutorial.MainActivity.java
com.example.yqltutorial.MemoryCache.java
com.example.yqltutorial.SingleItemView.java
com.example.yqltutorial.Utils.java