by zeeshan » Thu Mar 13, 2008 1:19 pm
package com.gps.framework.rivepoint.ListView;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
public class BulletedTextListAdapter extends BaseAdapter {
private Context mContext;
private List<BulletedText> mItems;
private boolean isFirst;
/**
*
* @param context
*/
public BulletedTextListAdapter(Context context) {
mContext = context;
mItems = new ArrayList<BulletedText>();
}
public void clear(Context context) {
mContext = context;
mItems = new ArrayList<BulletedText>();
}
/**
*
* @param bt
*/
public void addItem(BulletedText bt) {
mItems.add(bt);
}
/**
*
* @param bti
*/
public void setListItems(List<BulletedText> bti) {
mItems = bti;
}
/**
* The number of items in the
*/
public int getCount() {
return mItems.size();
}
/**
*
*/
public Object getItem(int position) {
return mItems.get(position);
}
/**
*
*/
public boolean areAllItemsSelectable() {
return false;
}
/**
*
*/
public boolean isSelectable(int position) {
return mItems.get(position).isSelectable();
}
/**
* Use the array index as a unique id.
*/
public long getItemId(int position) {
return position;
}
/**
* Make a BulletedTextView to hold each row.
*/
public View getView(int position, View convertView, ViewGroup parent) {
BulletedTextView btv;
if (convertView == null) {
btv = new BulletedTextView(mContext, mItems.get(position).getText(),
mItems.get(position).getBullet());
} else {
btv = (BulletedTextView) convertView;
btv.setText(mItems.get(position).getText());
btv.setBullet(mItems.get(position).getBullet());
}
return btv;
}
}
package com.gps.framework.rivepoint.ListView;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class BulletedTextView extends LinearLayout { //here i changed
private TextView mText;
private TextView mText1;
private ImageView mBullet;
public BulletedTextView(Context context) {
super(context);
}
public BulletedTextView(Context context, String text, Drawable bullet) {
super(context);
this.setOrientation(HORIZONTAL);
mBullet = new ImageView(context);
mBullet.setImageDrawable(bullet);
// left, top, right, bottom
//mBullet.setPadding(5, 0, 20, 50);
mBullet.setPadding(0, 0, 25, 0);
addView(mBullet, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
mText = new TextView(context);
mText.setPadding(0, 0, 0, 10);
mText.setText(text);
addView(mText, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
}
public void setText(String words) {
mText.setText(words);
}
public void setBullet(Drawable bullet) {
mBullet.setImageDrawable(bullet);
}
}
package com.gps.framework.rivepoint.ListView;
import android.graphics.drawable.Drawable;
public class BulletedText extends Object {
private String mText = "";//make it a collection to set more texts
private Drawable mBullet;
private boolean mSelectable = true;
/**
*
* @param text
* @param bullet
*/
public BulletedText(String text, Drawable bullet) {
mBullet = bullet;
mText = text;
}
/**
*
* @return
*/
public boolean isSelectable() {
return mSelectable;
}
/**
*
* @param selectable
*/
public void setSelectable(boolean selectable) {
mSelectable = selectable;
}
/**
*
* @return
*/
public String getText() {
return mText;
}
/**
*
* @param text
*/
public void setText(String text) {
mText = text;
}
/**
*
* @param bullet
*/
public void setBullet(Drawable bullet) {
mBullet = bullet;
}
/**
*
* @return
*/
public Drawable getBullet() {
return mBullet;
}
}
BulletedText bt1 = new BulletedText("GET COUPONS",getResources().getDrawable(R.drawable.icon_get_coupons));
BulletedText bt2 = new BulletedText("SEARCH POI",getResources().getDrawable(R.drawable.icon_search_coupons));
BulletedText bt3 = new BulletedText("SAVED COUPON",getResources().getDrawable(R.drawable.icon_save_coupons));
BulletedText bt4 = new BulletedText("MANAGE COUPON",getResources().getDrawable(R.drawable.icon_manage_coupons));
BulletedText bt5 = new BulletedText("SETTINGS",getResources().getDrawable(R.drawable.icon_settings_coupons));
btla.addItem(bt1);
btla.addItem(bt2);
btla.addItem(bt3);
btla.addItem(bt4);
btla.addItem(bt5);
setListAdapter(btla);