what have I done to my TextViews? - android

OK, so I have a cursor adapter that I cobbled together from various source and mostly seems to work -except my name fields. I have two checkboxes on a listview for each name but my names are all coming out the same (the first name)
Anyone spot the problem I've create? Your help would be appreciated.
public class MyDataAdapter extends SimpleCursorAdapter {
private Cursor c;
private Context context;
private ArrayList<String> list = new ArrayList<String>();
private ArrayList<Boolean> itemCheckedHere = new ArrayList<Boolean>();
private ArrayList<Boolean> itemCheckedLate = new ArrayList<Boolean>();
private ArrayList<Integer> itemCheckedIdx = new ArrayList<Integer>();
int idxCol;
int idx;
// itemChecked will store the position of the checked items.
public MyDataAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
c.moveToFirst();
for (int i = 0; i < c.getCount(); i++) {
itemCheckedHere.add(i, false); // initializes all items value with false
itemCheckedLate.add(i, false); // initializes all items value with false
}
}
public View getView(final int pos, View inView, ViewGroup parent) {
TextView studentName;
ImageView studentPhoto;
if (inView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inView = inflater.inflate(R.layout.show_attendance, null);
}
final CheckBox cBoxH = (CheckBox) inView.findViewById(R.id.attend);
final CheckBox cBoxL = (CheckBox) inView.findViewById(R.id.late);
// set up name field
studentName = (TextView) inView.findViewById(R.id.stuname);
if (studentName != null)
{
int index = c.getColumnIndex(gradeBookDbAdapter.KEY_NAME);
String name = c.getString(index);
studentName.setText(name);
}
cBoxH.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v.findViewById(R.id.attend);
if (cb.isChecked()) {
itemCheckedHere.set(pos, true);
// do some operations here
} else if (!cb.isChecked()) {
itemCheckedHere.set(pos, false);
// do some operations here
}
}
});
cBoxL.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v.findViewById(R.id.late);
if (cb.isChecked()) {
itemCheckedLate.set(pos, true);
// do some operations here
} else if (!cb.isChecked()) {
itemCheckedLate.set(pos, false);
// do some operations here
}
}
});
cBoxH.setChecked(itemCheckedHere.get(pos)); // this will Check or Uncheck the
cBoxL.setChecked(itemCheckedLate.get(pos)); // this will Check or Uncheck the
// CheckBox in ListView
// according to their original
// position and CheckBox never
// loss his State when you
// Scroll the List Items.
return inView;
}

The cursor in the adapter is not set to the correct row.
First of all you should get rid of your own member variables for the cursor and the context! Then try to implement the bindView method of the CursorAdapter, it will provide the cursor already set to the current row:
public class MyDataAdapter extends SimpleCursorAdapter {
private ArrayList<String> list = new ArrayList<String>();
private ArrayList<Boolean> itemCheckedHere = new ArrayList<Boolean>();
private ArrayList<Boolean> itemCheckedLate = new ArrayList<Boolean>();
private ArrayList<Integer> itemCheckedIdx = new ArrayList<Integer>();
// itemChecked will store the position of the checked items.
public MyDataAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
for (int i = 0; i < c.getCount(); i++) {
itemCheckedHere.add(i, false); // initializes all items value with false
itemCheckedLate.add(i, false); // initializes all items value with false
}
}
public void bindView (View inView, Context context, Cursor cursor){
super.bindView(inView,context,cursor);
TextView studentName;
ImageView studentPhoto;
//inView is never null in bindView
final CheckBox cBoxH = (CheckBox) inView.findViewById(R.id.attend);
final CheckBox cBoxL = (CheckBox) inView.findViewById(R.id.late);
// set up name field
studentName = (TextView) inView.findViewById(R.id.stuname);
if (studentName != null)
{
int index = cursor.getColumnIndex(gradeBookDbAdapter.KEY_NAME);
String name = cursor.getString(index);
studentName.setText(name);
}
//your other code
}
//other methods
}

You're going to kick yourself. You just forgot to move the cursor to the position corresponding to the index in the ListView:
c.moveToPosition(pos)

Related

Android AdapterView cannot display database records in some device

I would like to ask some question about AdapterView.
In my application, there is an activity which retrieve data from database and display them in AdapterView.
However, when i install the application in different devices, I found that the part I have just mentioned could only function on some devices. The others cannot show the database results.
Here is my code:
private void showResults(String query) {
Cursor cursor = searchCustByInputText(query);
if (cursor == null) {
//
} else {
// Specify the columns we want to display in the result
String[] from = new String[] {
"cust_code",
"chinese_name"};
// Specify the Corresponding layout elements where we want the columns to go
int[] to = new int[] {
R.id.scust_code,
R.id.schinese_name};
// Create a simple cursor adapter for the definitions and apply them to the ListView
SimpleCursorAdapter customers = new SimpleCursorAdapter(this,R.layout.cust_list_item, cursor, from, to);
mListView.setAdapter(customers);
// Define the on-click listener for the list items
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = (Cursor) mListView.getItemAtPosition(position);
String cust_code = c.getString(c.getColumnIndex("cust_code"));
if (callFromAct.equals("Main")) {
String pay_term = c.getString(c.getColumnIndex("pay_term"));
String chinese_name = c.getString(c.getColumnIndex("chinese_name"));
String english_name = c.getString(c.getColumnIndex("english_name"));
String address_1 = c.getString(c.getColumnIndex("address_1"));
String address_2 = c.getString(c.getColumnIndex("address_2"));
String address_3 = c.getString(c.getColumnIndex("address_3"));
String address_4 = c.getString(c.getColumnIndex("address_4"));
String contact = c.getString(c.getColumnIndex("contact"));
String telephone = c.getString(c.getColumnIndex("telephone"));
String last_order_date = c.getString(c.getColumnIndex("last_order_date"));
//Pass data to another Activity
Intent it = new Intent(CustEnqActivity.this, CustEnqDetailsActivity.class);
Bundle bundle = new Bundle();
bundle.putString("cust_code", cust_code);
bundle.putString("pay_term", pay_term);
bundle.putString("chinese_name", chinese_name);
bundle.putString("english_name", english_name);
bundle.putString("address_1", address_1);
bundle.putString("address_2", address_2);
bundle.putString("address_3", address_3);
bundle.putString("address_4", address_4);
bundle.putString("contact", contact);
bundle.putString("telephone", telephone);
bundle.putString("last_order_date", last_order_date);
it.putExtras(bundle);
startActivity(it);
}
else {
returnToCallingAct(cust_code);
}
//searchView.setQuery("",true);
}
});
}
}
Besides, I discovered there were two warnings in my logcat.
The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated
AdapterView is a raw type. References to generic type AdapterView should be parameterized
Are they related to the problem?
Try to create a class that extends BaseAdapter and use ViewHolders for performance
eg:
public class MyBaseAdapter extends BaseAdapter {
ArrayList<ListData> myList = new ArrayList<ListData>();
LayoutInflater inflater;
Context context;
public MyBaseAdapter(Context context, ArrayList<ListData> myList) {
this.myList = myList;
this.context = context;
inflater = LayoutInflater.from(this.context); // only context can also be used
}
#Override
public int getCount() {
return myList.size();
}
#Override
public ListData getItem(int position) {
return myList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
MyViewHolder mViewHolder;
if(convertView == null) {
convertView = inflater.inflate(R.layout.layout_list_item, null);
mViewHolder = new MyViewHolder();
convertView.setTag(mViewHolder);
} else {
mViewHolder = (MyViewHolder) convertView.getTag();
}
mViewHolder.tvTitle = detail(convertView, R.id.tvTitle, myList.get(position).getTitle());
mViewHolder.tvDesc = detail(convertView, R.id.tvDesc, myList.get(position).getDescription());
mViewHolder.ivIcon = detail(convertView, R.id.ivIcon, myList.get(position).getImgResId());
return convertView;
}
// or you can try better way
private TextView detail(View v, int resId, String text) {
TextView tv = (TextView) v.findViewById(resId);
tv.setText(text);
return tv;
}
private ImageView detail(View v, int resId, int icon) {
ImageView iv = (ImageView) v.findViewById(resId);
iv.setImageResource(icon); //
return iv;
}
private class MyViewHolder {
TextView tvTitle, tvDesc;
ImageView ivIcon;
}
}
More info/example:
http://www.pcsalt.com/android/listview-using-baseadapter-android/#sthash.lNGSCiyB.dpbs

Delete selected checkboxes

I am trying to get the selected checkboxes deleted. I have no clue what to do after this code below:
I am using a simple cursor adapter. I also want to know how I could select and deselect all the checkboxes. I had researched everything but can't find any answer. I've been stuck for 3 days. ALso, Im not sure if the code below is even the correct path i need.
public class SecondCheckedListView extends ListActivity {
private Cursor mCursor;
private Long mRowId;
DBAdapter db = new DBAdapter(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondcheckedlistview);
db.open();
fillData();
}
private void fillData() {
mCursor = db.getAllContacts();
startManagingCursor(mCursor);
String[] from = new String[]{DBAdapter.KEY_FIRSTNAME, DBAdapter.KEY_LASTNAME};
int[] to = new int[]{R.id.textView1, R.id.textView2};
SimpleCursorAdapter d =
new SimpleCursorAdapter(this, R.layout.rowcheckedlistview, mCursor, from, to);
setListAdapter(d);
}
public class MyAdapter extends SimpleCursorAdapter {
private final Context mContext;
private final int mLayout;
private final Cursor mCursor;
private final int mNameIndex;
private final int mIdIndex;
private final LayoutInflater mLayoutInflater;
private final class ViewHolder {
public TextView firstname;
public TextView lastname;
public CheckBox cBox;
}
public MyAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
this.mContext = context;
this.mLayout = layout;
this.mCursor = c;
this.mNameIndex = mCursor.getColumnIndex(DBAdapter.KEY_FIRSTNAME);
this.mIdIndex = mCursor.getColumnIndex(DBAdapter.ROW_ID);
this.mLayoutInflater = LayoutInflater.from(mContext);
}
#Override
public View getView(final int pos, View convertView, ViewGroup parent) {
if (mCursor.moveToPosition(pos)) {
ViewHolder viewHolder;
if(convertView == null) {
convertView = mLayoutInflater.inflate(mLayout, null);
viewHolder = new ViewHolder();
viewHolder.firstname = (TextView) convertView.findViewById(R.id.textView1);
viewHolder.lastname = (TextView) convertView.findViewById(R.id.textView2);
viewHolder.cBox = (CheckBox) convertView.findViewById(R.id.bcheck);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
String firstname = mCursor.getString(mNameIndex);
String rowId = mCursor.getString(mIdIndex);
}
return convertView;
}
}
}
what do you mean "delete"? You want to remove the checkbox from the listview? You might need
to do something like
viewHolder.RemoveView(cBox);
If you want to select/delsect all checkboxes, you'll probably want that based upon some other botton or checkbox. I do that with another checkbox like so:
private OnClickListener setSelectAllListener = new OnClickListener() {
#Override
public void onClick(View v) {
selectAllTouched = true;
if (!selectAllCheck.isChecked()) {
selectAll = false;
studs.notifyDataSetChanged();
}
else {
selectAll = true;
studs.notifyDataSetChanged();
}
}
};
And then in my custom adapter that does stuff with each checkbox in a listview, I use this:
if (selectAllTouched) {
if(selectAll){
holder.here.setChecked(true);
itemCheckedHere.set(pos, true);
int who= new Integer(holder.text2.getText().toString());
mDbHelper.updateAttend(who, classnum, ATTEND, 1, attendDate );
}
else{
holder.here.setChecked(false);
itemCheckedHere.set(pos, false);
int who = new Integer(holder.text2.getText().toString());
mDbHelper.updateAttend(who, classnum, ATTEND, 0, attendDate );
}
}
I used a sparse array, itemCheckedHere, to hold the values of all the check boxes so scrolling doesn't change the values on resued views.

Return filename from SimpleCursorAdapter to Activity

I wanna return a particular filename from a simplecursoradapter back to the activity from which it was called.
I tried this link How communicate between Adapter and Activity and also this one Data between activity and adapter
But either didnt hel p me. I am posting both the activity code and adapter code here.Kindly help
Activity
videolist = (ListView) findViewById(R.id.VideoMusicList);
videolist.setAdapter(adapter);
//Adapter
public class SdCardAdapter extends SimpleCursorAdapter {
static final String TAG = "[SongListAdapter]";
int position;
CheckBox media_selected;
final String SETTING_TODOLIST = "todolist";
private String chk;
private Context context;
private Object itemText;
private ArrayList<string> selectedItems = new ArrayList<string>();
// String file;
private Object convertView;
// private final List<Model> list;
int count;
ListView listview;
private List<Model> list;
private Cursor videocursor;
private LayoutInflater mInflater;
private OnClickListener mClick;
private OnCheckedChangeListener mChecked;
String file_rel_path;
String file_abs_path;
String last_file;
/**
* The Class ViewHolder.
*/
static class ViewHolder {
/** The sdcard_item. Layout of each item in the list view */
RelativeLayout sdcard_item;
LinearLayout sdcard;
/** The title. Textview to display the song title */
TextView media_name;
CheckBox media_selected;
ListView listview;
int position;
}
public SdCardAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View v = super.newView(context, cursor, parent);
final Cursor filecursor = cursor;
final ViewHolder vh = new ViewHolder();
vh.media_name = (TextView) v.findViewById(R.id.sdcard_title);
position = cursor.getPosition();
count = cursor.getCount();
vh.media_selected = (CheckBox) v.findViewById(R.id.sdcard_checkbox);
vh.media_selected
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
System.out.println("checkbox ckicked......");
if (vh.media_selected.isChecked()) {
vh.media_selected.setId(1);
vh.media_selected.getId();
last_file = file_rel_path;
file_rel_path = vh.media_name.getText().toString();
Log.d("filename_........", file_rel_path);
v.setBackgroundColor(Color.GRAY);
} else if (!vh.media_selected.isChecked()) {
file_rel_path="";
vh.media_selected.setId(0);
vh.media_selected.getId();
v.setBackgroundColor(Color.BLACK);
}
Log.d("Position", "" + position);
for (int i = 0; i < count; i++) {
filecursor.moveToPosition(i);
file_abs_path = filecursor.getString(filecursor
.getColumnIndex(MediaStore.Video.Media.TITLE));
if (file_abs_path.equals(file_rel_path)) {
String file_path = filecursor.getString(filecursor
.getColumnIndex(MediaStore.Video.Media.DATA));
Log.d("filename.......", file_path);
}
}
}
});
vh.sdcard_item = (RelativeLayout) v.findViewById(R.id.sdcard_item);
v.setTag(vh);
return v;
}
}
//This is the string that i want to pass to my previous activity
String file_path = filecursor.getString(filecursor.getColumnIndex(MediaStore.Video.Media.DATA));
Use interface callBack :
In SdCardAdapter class create interface :
public interface SdCardAdapterListener
{
public void sendFilePath(String path);
}
Add a listener param in SdCardAdapter constructor :
private SdCardAdapterListener delegate;
public SdCardAdapter(Context context, int layout, Cursor c, String[] from,
int[] to, SdCardAdapterListener delegate)
{
super(context, layout, c, from, to);
this.delegate = delegate;
}
In Activity :
SdCardAdapter adapter = new SdCardAdapter(this, layout, c, from, to, new SdCardAdapterListener()
{
#Override
public void sendFilePath(String path)
{
// do something with path
}
});
videolist = (ListView) findViewById(R.id.VideoMusicList);
videolist.setAdapter(adapter);
Then, simply call delegate.sendFilePath(path) in SdCardAdapter for send to sendFilePath method in your Activity.

Custom ListView with CheckBox

I know there are lots of questions related to Custom ListView with CheckBox but still i am getting some problem in retrieving all checked items.
What i am doing is :
Displaying Custom ListView from Database (List of All Sent SMSs).
Allow user to check various list items.
When user presses the Delete Button i want to delete all the checked items (From the database as well as the view portion)
Problem :
When i go to my Activity for the first time and check some items, and delete it, it works fine.
But when i again check some items just after pressing delete button, some items gets checked and some gets unchecked and again some other items are deleted..
I think i am not able to bind id and list item perfectly..
Coding done so far:
row.xml contains
ImageView
TextView
TextView
TextView
CheckBox
In my Activity Class :
Uri uriSms = Uri.parse("content://sms/sent");
Cursor cursor = context.getContentResolver().query(uriSms, null,null,null,null);
String[] from={"address","body"};
int[] to={R.id.contactName,R.id.msgLine};
ssa=new SentSmsAdapter(context,R.layout.inbox_list_item,cursor,from,to,2);
smsList.setAdapter(ssa);
deleteSms.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
ArrayList<Boolean> list=SentSmsAdapter.itemChecked;
Uri path=Uri.parse("content://sms/");
for(int i=0;i<list.size();i++)
{
if(list.get(i))
getContentResolver().delete(path,"_id="+ssa.getItemId(i),null);
}
ssa.notifyDataSetChanged();
}
I have custom SimpleCursorAdapter.
public class SentSmsAdapter extends SimpleCursorAdapter{
Cursor dataCursor;
LayoutInflater mInflater;
Context context;
int layoutType;
ArrayList<String> arrayList;
public static HashMap<String,Long> myList=new HashMap<String,Long>();
public static ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
public static ArrayList<Long> itemIds=new ArrayList<Long>();
public SentSmsAdapter(Context context, int layout, Cursor dataCursor, String[] from,
int[] to,int type) {
super(context, layout, dataCursor, from, to);
layoutType=type;
this.context=context;
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
arrayList=new ArrayList<String>();
for (int i = 0; i < this.getCount(); i++) {
itemChecked.add(i, false);
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null)
{
convertView = mInflater.inflate(R.layout.inbox_list_item, null);
holder = new ViewHolder();
holder.checkBox=(CheckBox) convertView.findViewById(R.id.checkMsg);
holder.checkBox.setTag(position);
holder.cName=(TextView)convertView.findViewById(R.id.contactName);
holder.icon=(ImageView)convertView.findViewById(R.id.msgImage);
holder.msg=(TextView)convertView.findViewById(R.id.msgLine);
holder.time=(TextView)convertView.findViewById(R.id.msgTime);
convertView.setTag(holder);
holder.checkBox.setTag(itemChecked.get(position));
}
else
{
holder=(ViewHolder)convertView.getTag();
}
holder.checkBox.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
CheckBox cb = (CheckBox) view.findViewById(R.id.checkMsg);
int pos=Integer.parseInt(holder.checkBox.getTag());
itemChecked.set(position, cb.isChecked());
/*if (cb.isChecked()) {
itemChecked.set(position, true);
Log.i("WhenChecked",Boolean.toString(itemChecked.get(position)));
// do some operations here
}
else if (!cb.isChecked()) {
itemChecked.set(position, false);
Log.i("WhenNotChecked",Boolean.toString(itemChecked.get(position)));
// do some operations here
}
*/
}
});
dataCursor.moveToPosition(position);
String id=Integer.toString(dataCursor.getInt(dataCursor.getColumnIndexOrThrow("_id")));
itemIds.add(Long.parseLong(id));
String msgText=dataCursor.getString(dataCursor.getColumnIndexOrThrow("body"));
holder.msg.setText(msgText);
Long time=dataCursor.getLong(dataCursor.getColumnIndexOrThrow("date"));
holder.time.setText(Long.toString(time));
String address=dataCursor.getString(dataCursor.getColumnIndexOrThrow("address"));
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
Cursor cs= context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null,null,null);
if(cs.getCount()>0)
address=cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
cs.close();
holder.cName.setText(address);
if(layoutType==1)holder.checkBox.setVisibility(View.GONE);
else
{
holder.checkBox.setVisibility(View.VISIBLE);
}
arrayList.add(id+","+address+","+msgText+","+Long.toString(time));
return convertView;
}
static class ViewHolder
{
ImageView icon;
CheckBox checkBox;
TextView cName;
TextView msg;
TextView time;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrayList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return itemIds.get(position);
}
}
Try something like this.
add this code in getView()
holder.checkBox.seTag(position);
holder.checkBox.setOnCheckedChangedListener(this);
implement this outside getView().
public void onCheckedChanged(CompoundButton view,boolean isChecked) {
if(isChecked)
{
itemChecked.add(view.getTag());
}
else
{
if(itemChecked.cantains(view.getTag()))
//remove from itemChecked.
}
}
When deleting delete all the elements from the list whose index is available in itemChecked.
Thanks and N-JOY.
If you use threads when checking, uncheking and deleting your items, they will work properly.

Retrieve checked CheckBoxes's items in Listview

I've got ListActivity and I am using custom CursorAdapter.
In each item of the list I've got also checkbox...
Now I have in my list screen a perm button, when you press on it,
It should find all the checkboxes which are 'checked' and do some operations on the item which it's checkbox is 'checked'.
How can I retrieve all the checked ones?
I've done focusable:false, so I can use OnClickListener, but I don't know how farther then
this..
Thanks,
some code:
This is in my ListActivity class:
final String columns[] = new String[] { MyUsers.User._ID,
MyUsers.User.MSG, MyUsers.User.LOCATION };
int[] to = new int[] { R.id.toptext, R.id.bottomtext,R.id.ChkBox,
R.id.Location};
Uri myUri = Uri.parse("content://com.idan.datastorageprovider/users");
Cursor cursor = getContentResolver().query(myUri, columns, null, null, null);
startManagingCursor(cursor);
ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this,R.layout.listitem, cursor, columns, to);
this.setListAdapter(myCursorAdapter);
and this is my Custom Cursor adapter class:
public class ListCursorAdapter extends SimpleCursorAdapter
{
private Context context;
private int layout;
public ListCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to)
{
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
return v;
}
#Override
public void bindView(View v, Context context, Cursor c)
{
TextView topText = (TextView) v.findViewById(R.id.toptext);
if (topText != null)
{
topText.setText("");
}
int nameCol = c.getColumnIndex(MyUsers.User.MSG);
String name = c.getString(nameCol);
TextView buttomTxt = (TextView) v.findViewById(R.id.bottomtext);
if (buttomTxt != null)
{
buttomTxt.setText("Message: "+name);
}
nameCol = c.getColumnIndex(MyUsers.User.LOCATION);
name = c.getString(nameCol);
TextView location = (TextView) v.findViewById(R.id.Location);
if (locationLinkTxt != null)
{
locationLinkTxt.setText(name);
}
}
//Modify to meet your needs
String[] from = new String[]{ YourDbAdapter.KEY_WORDS_ROWID, YourDbAdapter.KEY_WORDS_ROWID};
int[] to = new int[]{ R.id.row_item_checkbox};
mAdapter = new SimpleCursorAdapter(this, R.layout.row_item_with_checkbox, yourDbCursor, from, to);
mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view.getId() == R.id.myCheckbox )
{
CheckBox cb = (CheckBox) view;
cb.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final long id = cursor.getLong(columnIndex); //Your row id
//You can do the necessary work here such as adding to an List or somehting
}
});
return true;
}
return false;
}
});

Categories

Resources