by zeeshan » Mon Apr 07, 2008 7:37 am
This is the actitvity code ...
setContentView(R.layout.main);
BulletedText bt1 = new BulletedText("BROWSE COUPONS",getResources().getDrawable(R.drawable.icon_get_coupons));
BulletedText bt2 = new BulletedText("SEARCH ",getResources().getDrawable(R.drawable.icon_search_coupons));
BulletedText bt3 = new BulletedText("SAVED COUPONS",getResources().getDrawable(R.drawable.icon_save_coupons));
BulletedText bt4 = new BulletedText("MANAGE COUPONS",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);
setSelection(0);
setListAdapter(btla);
setSelection(0);
this is the layout code
package com.gps.framework.rivepoint.ListView;
import com.gps.framework.rivepoint.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewInflate;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
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);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT);
params.setMargins(5, 3, 5, 0);
this.setOrientation(HORIZONTAL);
mBullet = new ImageView(context);
mBullet.setImageDrawable(bullet);
// left, top, right, bottom
//mBullet.setPadding(5, 0, 20, 50);
mBullet.setPadding(0, 10, 25, 0);
/*addView(mBullet, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));*/
addView(mBullet, params);
mText = new TextView(context);
//mText.setBackground(R.layout.tab_indicator);
//mText.setTextColor(R.color.tab_indicator_text);
mText.setPadding(0, 0, 0, 10);
mText.setText(text);
mText.setGravity(Gravity.BOTTOM);
//mText.setBackground(R.drawable.tab_indicator);
//mText.seti
//View tab = ViewInflate.from(context).inflate(R.layout.tab_indicator, this, null);
//TextView tv = (TextView)tab.findViewById(R.id.tab_label);
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);
}
}
this is the adaptor code...
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);
notifyDataSetChanged();
}
/**
*
* @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;
}
}
this is the xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="10sp"
>
<LinearLayout android:name="@+id/top_container"
android:orientation="horizontal" android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:src="@drawable/toplogo" android:layout_gravity="center_vertical" />
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/empty" />
<TextView android:layout_width="fill_parent" android:id="@+id/title"
android:layout_height="wrap_content" android:text="@string/empty"
android:layout_gravity="center_vertical" style="@style/Title_Style"
android:padding="5sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/empty" />
<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sorry! No Coupons available" />
<ListView android:id="@+id/android:list"
android:scrollbars="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview" style="@style/tabIndicatorText"
android:listSelector="@drawable/tab_indicator_text"
/>
<LinearLayout android:name="@+id/top_container"
android:orientation="horizontal" android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:src="@drawable/shape_5" android:layout_weight="1"
android:background="@drawable/shape_5" />
</LinearLayout>
</LinearLayout>