I am trying  check box inside list, like iconified List, but Null
pointer exception is coming, can anybody Tell me , where is the
error...

Here is the code,


import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.widget.CheckBox;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CheckBoxifiedList extends ListActivity {

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Context mContext = this;
        CheckBox c1 = new CheckBox(mContext);
        CheckBox c2 = new CheckBox(mContext);
        CheckBox c3 = new CheckBox(mContext);
        CheckBox c4 = new CheckBox(mContext);

        CheckTextListAdapter btla = new CheckTextListAdapter(this);
        CheckText bt1 = new CheckText("Google", c1);
        CheckText bt2 = new CheckText("Mail", c2);
        CheckText bt3 = new CheckText("Explorer", c3);
        CheckText bt4 = new CheckText("Messenger", c4);
        btla.addItem(bt1);
        btla.addItem(bt2);
        btla.addItem(bt3);
        btla.addItem(bt4);
        setListAdapter(btla);
    }

    class CheckText extends Object {

        private String mText = "";
        Context mContext = this.mContext;
        CheckBox cBullet = new CheckBox(mContext);
        private boolean mSelectable = true;

        public CheckText(String text, CheckBox bullet) {
            cBullet = bullet;
            mText = text;

        }

        public boolean isSelectable() {
            return mSelectable;
        }

        public void setSelectable(boolean selectable) {
            mSelectable = selectable;
        }

        public String getText() {
            return mText;
        }

        public void setText(String text) {
            mText = text;
        }

        public void setBullet(CheckBox bullet) {
            cBullet = bullet;
        }

        public CheckBox getBullet() {
            return cBullet;
        }
    }

    class CheckTextListAdapter extends BaseAdapter {

        private Context mContext;
        private List<CheckText> mItems;

        public CheckTextListAdapter(Context context) {
            mContext = context;
            mItems = new ArrayList<CheckText>();
        }

        void addItem(CheckText bt) {
            mItems.add(bt);

        }

        void setListItems(List<CheckText> bti) {
            mItems = bti;
        }

        public int getCount() {
            return mItems.size();
        }

        public Object getItem(int position) {
            return mItems.get(position);
        }

        @Override
        public boolean areAllItemsSelectable() {
            return false;
        }

        @Override
        public boolean isSelectable(int position) {
            return mItems.get(position).isSelectable();
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup
parent) {
            CheckTextView btv;
            if (convertView == null) {
                btv = new CheckTextView(mContext,
mItems.get(position).getText(),
                        mItems.get(position).getBullet());
            } else {
                btv = (CheckTextView) convertView;
                btv.setText(mItems.get(position).getText());
                btv.setBullet(mItems.get(position).getBullet());
            }
            return btv;
        }
    }

    class CheckTextView extends LinearLayout {

        private TextView mText;
        private CheckBox mBullet;

        public CheckTextView(Context context, String text, CheckBox
bullet) {
            super(context);
            this.setOrientation(HORIZONTAL);
            mBullet = new CheckBox(context);
            mBullet = bullet;
            addView(mBullet, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
            mText = new TextView(context);
            mText.setText(text);
            addView(mText, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
        }

        public void setText(String words) {
            mText.setText(words);
        }

        public void setBullet(CheckBox c) {
            mBullet = c;
        }
    }
}


Thanks
Nithin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to