Maillist class
Using java Syntax Highlighting
- package com.google;
- import java.util.ArrayList;
- import java.util.List;
- import com.google.ClickableListAdapter.ViewHolder;
- import android.app.Dialog;
- import android.app.ListActivity;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.TableRow;
- import android.widget.TextView;
- /**
- * An example how to implement the ClickableListAdapter for a list view layout containing
- * a TextView and an ImageView.
- * @author poss3x
- */
- public class mailslist extends ListActivity {
- Dialog dialog;// = new Dialog(this);
- /**
- * Our data class. This data will be bound to
- * MyViewHolder, which in turn is used for the
- * ListView.
- */
- static class MyData {
- public MyData(String t,String t1,String t2, boolean e) {
- text = t;
- text1 = t1;
- text2 = t2;
- enable = e;
- }
- String text,text1,text2;
- Bitmap i1;
- boolean enable;
- }
- /**
- * Our very own holder referencing the view elements
- * of our ListView layout
- */
- static class MyViewHolder extends ViewHolder {
- public MyViewHolder(TextView t,TextView t1,TextView t2) {
- sub = t;
- from=t1;
- date=t2;
- }
- TextView sub;
- TextView from;
- TextView date;
- }
- /**
- * The implementation of ClickableListAdapter
- */
- private class MyClickableListAdapter extends ClickableListAdapter {
- public MyClickableListAdapter(Context context, int viewid,
- List<MyData> objects) {
- super(context, viewid, objects);
- // nothing to do
- }
- protected void bindHolder(ViewHolder h) {
- // Binding the holder keeps our data up to date.
- // In contrast to createHolder this method is called for all items
- // So, be aware when doing a lot of heavy stuff here.
- // we simply transfer our object's data to the list item representatives
- MyViewHolder mvh = (MyViewHolder) h;
- MyData mo = (MyData)mvh.data;
- mvh.sub.setText(mo.text);
- mvh.from.setText(mo.text1);
- mvh.date.setText(mo.text2);
- }
- @Override
- protected ViewHolder createHolder(View v) {
- // createHolder will be called only as long, as the ListView is not filled
- // entirely. That is, where we gain our performance:
- // We use the relatively costly findViewById() methods and
- // bind the view's reference to the holder objects.
- /* TextView text = (TextView) v.findViewById(R.id.text);
- ImageButton button = (ImageButton) v.findViewById(R.id.Button);*/
- TextView sub = (TextView) v.findViewById(R.id.lblSubject);
- TextView from = (TextView) v.findViewById(R.id.lblfrom);
- TextView date = (TextView) v.findViewById(R.id.lbldate);
- ViewHolder mvh = new MyViewHolder(sub,from,date);
- // Additionally, we make some icons clickable
- // Mind, that item becomes clickable, when adding a click listener (see API)
- // so, it is not necessary to use the android:clickable attribute in XML
- sub.setOnClickListener(new ClickableListAdapter.OnClickListener(mvh) {
- public void onClick(View v, ViewHolder viewHolder) {
- // we toggle the enabled state and also switch the icon
- /* MyViewHolder mvh = (MyViewHolder) viewHolder;
- MyData mo = (MyData) mvh.data;
- mo.enable = !mo.enable; // toggle
- ImageView icon = (ImageView) v;
- icon.setImageBitmap(
- mo.enable ? mailslist.this.mIconEnabled
- : mailslist.this.mIconDisabled);*/
- MyViewHolder mvh = (MyViewHolder) viewHolder;
- MyData mo = (MyData)mvh.data;
- // we toggle an '*' in our text element
- String s = mo.text;
- if (s.charAt(0) == '*') {
- mo.text = s.substring(1);
- } else {
- mo.text = '*' + s;
- }
- mvh.sub.setText(mo.text);
- //try onlick (intent) here
- }
- });
- // for text we implement a long click listener
- sub.setOnLongClickListener(new ClickableListAdapter.OnLongClickListener(mvh) {
- @Override
- public void onLongClick(View v, ViewHolder viewHolder) {
- MyViewHolder mvh = (MyViewHolder) viewHolder;
- MyData mo = (MyData)mvh.data;
- // we toggle an '*' in our text element
- String s = mo.text;
- if (s.charAt(0) == '*') {
- mo.text = s.substring(1);
- } else {
- mo.text = '*' + s;
- }
- mvh.sub.setText(mo.text);
- /* dialog.setContentView(R.layout.contextdialog);
- dialog.setTitle("Current Context");
- dialog.show();*/
- }
- });
- return mvh; // finally, we return our new holder
- }
- protected void disp() {
- // TODO Auto-generated method stub
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // fill list with some items...
- // to demonstrate the performance we create a bunch of data objects
- for (int i = 0; i < 10; ++i) {
- //if ka logic laga na hai ider
- //if(i%2) 24 feb(00 hrs)
- mObjectList.add(new MyData("Subject" + i,"abc"+i+"@gmail.com", +i+" Days ago",true));
- }
- //here we set our adapter
- setListAdapter(new MyClickableListAdapter(this,
- R.layout.maillist, mObjectList));
- }
- // --------------- field section -----------------
- private Bitmap mIconEnabled;
- private Bitmap mIconDisabled;
- public List<MyData> mObjectList=new ArrayList<MyData>();
- }
Parsed in 0.055 seconds, using GeSHi 1.0.8.4
abstract class ClickableAdapter
Using java Syntax Highlighting
- package com.google;
- import java.util.ArrayList;
- import java.util.List;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- public abstract class ClickableListAdapter extends BaseAdapter {
- private LayoutInflater mInflater;
- private List mDataObjects; // our generic object list
- private int mViewId;
- /**
- * This is the holder will provide fast access to arbitrary objects and
- * views. Use a subclass to adapt it for your personal needs.
- */
- public static class ViewHolder {
- // back reference to our list object
- public Object data;
- public Object icon;
- }
- /**
- * The click listener base class.
- */
- public static abstract class OnClickListener implements
- View.OnClickListener {
- private ViewHolder mViewHolder;
- /**
- * @param holder The holder of the clickable item
- */
- public OnClickListener(ViewHolder holder) {
- mViewHolder = holder;
- }
- // delegates the click event
- public void onClick(View v) {
- onClick(v, mViewHolder);
- }
- /**
- * Implement your click behavior here
- * @param v The clicked view.
- */
- public abstract void onClick(View v, ViewHolder viewHolder);
- };
- /**
- * The long click listener base class.
- */
- public static abstract class OnLongClickListener implements
- View.OnLongClickListener {
- private ViewHolder mViewHolder;
- /**
- * @param holder The holder of the clickable item
- */
- public OnLongClickListener(ViewHolder holder) {
- mViewHolder = holder;
- }
- // delegates the click event
- public boolean onLongClick(View v) {
- onLongClick(v, mViewHolder);
- return true;
- }
- /**
- * Implement your click behavior here
- * @param v The clicked view.
- */
- public abstract void onLongClick(View v, ViewHolder viewHolder);
- };
- /**
- * @param context The current context
- * @param viewid The resource id of your list view item
- * @param objects The object list, or null, if you like to indicate an empty
- * list
- */
- public ClickableListAdapter(Context context, int viewid, List objects) {
- // Cache the LayoutInflate to avoid asking for a new one each time.
- mInflater = LayoutInflater.from(context);
- mDataObjects = objects;
- mViewId = viewid;
- if (objects == null) {
- mDataObjects = new ArrayList<Object>();
- }
- }
- /**
- * The number of objects in the list.
- */
- public int getCount() {
- return mDataObjects.size();
- }
- /**
- * @return We simply return the object at position of our object list Note,
- * the holder object uses a back reference to its related data
- * object. So, the user usually should use {@link ViewHolder#data}
- * for faster access.
- */
- public Object getItem(int position) {
- return mDataObjects.get(position);
- }
- /**
- * We use the array index as a unique id. That is, position equals id.
- *
- * @return The id of the object
- */
- public long getItemId(int position) {
- return position;
- }
- /**
- * Make a view to hold each row. This method is instantiated for each list
- * object. Using the Holder Pattern, avoids the unnecessary
- * findViewById()-calls.
- */
- public View getView(int position, View view, ViewGroup parent) {
- // A ViewHolder keeps references to children views to avoid uneccessary
- // calls
- // to findViewById() on each row.
- ViewHolder holder;
- // When view is not null, we can reuse it directly, there is no need
- // to reinflate it. We only inflate a new View when the view supplied
- // by ListView is null.
- if (view == null) {
- view = mInflater.inflate(mViewId, null);
- // call the user's implementation
- holder = createHolder(view);
- // we set the holder as tag
- view.setTag(holder);
- } else {
- // get holder back...much faster than inflate
- holder = (ViewHolder) view.getTag();
- }
- // we must update the object's reference
- holder.data = getItem(position);
- // call the user's implementation
- bindHolder(holder);
- return view;
- }
- /**
- * Creates your custom holder, that carries reference for e.g. ImageView
- * and/or TextView. If necessary connect your clickable View object with the
- * PrivateOnClickListener, or PrivateOnLongClickListener
- *
- * @param vThe view for the new holder object
- */
- protected abstract ViewHolder createHolder(View v);
- /**
- * Binds the data from user's object to the holder
- * @param h The holder that shall represent the data object.
- */
- protected abstract void bindHolder(ViewHolder h);
- }
Parsed in 0.047 seconds, using GeSHi 1.0.8.4
These are my classes plz tell me how to intent another class on "onClick" event.

