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.example.yqltutorial;
//from  ww  w.  j  a  v a 2s .  c o m
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
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 tweets;
    ImageView pimage;

    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
    tweets = (TextView) itemView.findViewById(R.id.tweets);

    // Locate the ImageView in listview_item.xml
    pimage = (ImageView) itemView.findViewById(R.id.pimage);

    // Capture position and set results to the TextViews using Html.fromHtml to show special characters
    tweets.setText(Html.fromHtml(resultp.get(MainActivity.TWEETS)));

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

    // 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 tweets
        intent.putExtra("tweets", resultp.get(MainActivity.TWEETS));
        // Pass all data pimage
        intent.putExtra("pimage", resultp.get(MainActivity.PIMAGE));
        // 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