Thanks Jose, That helps.

I am also trying to change the CheckBox style. Get rid of the box or
maybe fade it out and give the checkmark more focus, etc. Would you
know how to change the checkbox style and not use the default?

Thanks,

Abhishek

On Dec 14, 9:01 pm, Jose Gomez <j...@josecgomez.com> wrote:
> Hey I just wrote something like this I couldn't find any examples either but
> I can give you some pointers.
>
> Declare your List View Layout
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android";
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> android:orientation="vertical">
> <ImageView
> android:src="@drawable/groshielogo"
>  android:layout_width="wrap_content"
> android:layout_height="wrap_content"
>  android:paddingBottom="20px"
> android:paddingTop="20px"
>  android:layout_gravity="center"
> />
> <ListView
>  android:id="@+id/lvItems"
> android:layout_width="fill_parent"
>  android:layout_height="wrap_content"
> android:choiceMode="singleChoice"
>  android:focusable="true"
> android:clickable="true"
> android:longClickable="true"
>  >
> </ListView>
> </LinearLayout>
>
> Declare another layout file for the specific rows.in my cae I have a checkbx
> and two textvies but it should be obvious how to change it just add or
> remove fields.
>
>  <TableLayout
>    xmlns:android="http://schemas.android.com/apk/res/android";
>  android:layout_width="fill_parent"
> android:layout_height="fill_parent"
>   >
>   <TableRow
>   android:layout_width="fill_parent"
>   android:layout_height="wrap_content"
>   >
>   <CheckBox
>   android:layout_width="wrap_content"
>   android:layout_height="wrap_content"
>   android:id="@+id/rowItemBought"
>   android:paddingRight="10px"
>   />
>   <TextView
>   android:layout_width="fill_parent"
>   android:layout_height="wrap_content"
>   android:id="@+id/rowItemName"
>   android:paddingRight="10px"
>   />
>   <TextView
>   android:layout_width="fill_parent"
>   android:layout_height="wrap_content"
>   android:id="@+id/rowItemPrice"
>   android:paddingRight="10px"
>   />
>   </TableRow>
>   </TableLayout>
>
> Then if you are trying to  get the information out of a custom class say in
> my case the shopping list class you need to create a custom Array Adapter
> that will utilize this layout
> at the bottom you see where I assign the different fields like the 2
> textviews and the checkbox to a particular field in the class.
>
> package unf.edu.esifall09.team1;
> import java.util.List;
>
> import unf.edu.esifall09.team1.R;
> import android.content.Context;
> import android.view.LayoutInflater;
> import android.view.View;
> import android.view.ViewGroup;
> import android.widget.ArrayAdapter;
> import android.widget.CheckBox;
> import android.widget.LinearLayout;
> import android.widget.TextView;
>
> public class ShoppingListAdapter extends ArrayAdapter<ShoppingListItems> {
>
> int resource;
> public ShoppingListAdapter(Context context, int resource,
> List<ShoppingListItems> items)
>  {
> super(context, resource,items);
> this.resource=resource;
>  }
> �...@override
>  public View getView(int position, View convertView, ViewGroup parent)
> {
> LinearLayout shoppingListItemView;
>  ShoppingListItems sli =getItem(position);
>  String prodName =sli.getItemDescription();
> double price = sli.getPrice();
>  boolean purchases = sli.isPurchased();
>  if(convertView==null)
>  {
> shoppingListItemView = new LinearLayout(getContext());
> String inflater = Context.LAYOUT_INFLATER_SERVICE;
>  LayoutInflater vi;
> vi = (LayoutInflater)getContext().getSystemService(inflater);
>  vi.inflate(resource, shoppingListItemView, true);}
>
> else
>  {
> shoppingListItemView = (LinearLayout) convertView;}
>
>  CheckBox chkPurchased =
> (CheckBox)shoppingListItemView.findViewById(R.id.rowItemBought);
>  TextView itemName
> =(TextView)shoppingListItemView.findViewById(R.id.rowItemName);
> TextView itemPrice
> =(TextView)shoppingListItemView.findViewById(R.id.rowItemPrice);
>  chkPurchased.setChecked(purchases);
> itemName.setText(prodName);
> itemPrice.setText(Double.toString(price));
>  return shoppingListItemView;
>  }
>
> }
>
> Ofter that is created go to the activity where you will like your ListView
>
> Declare your Variables
> ArrayList<ShoppingListItems> items;
> ShoppingListAdapter adapter;
> ListView lv;
>
> Then on create set up your list view and your adapters
>
> public void onCreate(Bundle savedInstanceState) {
>  super.onCreate(savedInstanceState);
>
> lv=(ListView)findViewById(R.id.lvItems);
> items= new ArrayList<ShoppingListItems>();
>
> do a loop of some sort to fill in your adapter. Like in my case I read form
> a Database
>
> Cursor itemsCur=productsDb.getAllShoppingListItemsCursor(shoppingListPK);
>  do{
> ShoppingListItems sli = new ShoppingListItems();
> sli.setItemDescription(itemsCur.getString(2));
>  sli.setPrice(itemsCur.getDouble(4));
> sli.setPurchased((itemsCur.getInt(7))==0?false:true);
>  sli.setQuantity(itemsCur.getDouble(5));
> sli.setShoppingListItemPK(itemsCur.getInt(0));
>  sli.setShoppingListPK(itemsCur.getInt(1));
> sli.setStorePK(itemsCur.getInt(6));
>  sli.setUpc(itemsCur.getString(3));
> items.add(sli);
>
> }while(itemsCur.moveToNext());
>
> Set the data into your adapter and add to the List View
> adapter= new ShoppingListAdapter(this, R.layout.shippinglistitem, items);
> lv.setAdapter(adapter);
>
> }
>
> That should do it Hopefully it makes sense!
>
> Sincerely
> Jose C Gomez
>
> http://www.josecgomez.com
>
>
>
> On Mon, Dec 14, 2009 at 8:09 PM, Abhi <abhishek.r.sha...@gmail.com> wrote:
> > Hi,
>
> > I am looking to create a custom ListView with 6 fixed items in the
> > list. Each list row comprising of the checkbox, image icon and a
> > single line of text. I have read couple of tutorials but none of them
> > seem to be that well explanatory. Could someone please guide me to a
> > sample code? That would be great help.
>
> > Thanks,
>
> > Abhishek
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubs­cr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to