I'm pretty new to android and I've got a question. I'm playing around with a simple Twitter client tutorial which is on github. however I can't manage to get a onClickListener
working properly. How can I retrieve the position of any item on the list that is being clicked on?
I've tried playing around by combining tutorials with no luck yet.
Here is the code: https://github.com/cacois/TweetView/blob/progress_bar/src/com/example/TweetItemAdapter.java
package com.example; import java.util.ArrayList; import com.example.Example.Tweet; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; public class TweetItemAdapter extends ArrayAdapter<Tweet> { private ArrayList<Tweet> tweets; private Activity activity; public ImageManager imageManager; public TweetItemAdapter(Activity a, int textViewResourceId, ArrayList<Tweet> tweets) { super(a, textViewResourceId, tweets); this.tweets = tweets; activity = a; imageManager = new ImageManager(activity.getApplicationContext()); } public static class ViewHolder{ public TextView username; public TextView message; public ImageView image; public ProgressBar progress; //ADDED } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; ViewHolder holder; if (v == null) { LayoutInflater vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.listitem, null); holder = new ViewHolder(); holder.username = (TextView) v.findViewById(R.id.username); holder.message = (TextView) v.findViewById(R.id.message); holder.image = (ImageView) v.findViewById(R.id.avatar); holder.progress = (ProgressBar) v.findViewById(R.id.progress_bar); //ADDED v.setTag(holder); } else holder=(ViewHolder)v.getTag(); final Tweet tweet = tweets.get(position); if (tweet != null) { holder.username.setText(tweet.username); holder.message.setText(tweet.message); holder.image.setTag(tweet.image_url); imageManager.displayImage(tweet.image_url, activity, holder.image, holder.progress); //CHANGED } return v; } }