Thanks buddy, but it still doesn't work in my case, now i will attach more
informatin below.
My Adapter class
public class ProfileAdapter extends SimpleAdapter {
Activity mContext;
CheckBox cb;
ProfileDAO mProfileDao;
int mId;
int mPosition;
public ProfileAdapter(Activity context, List<Map<String, String>>
rowList, int resourceId, String[] from, int[] to) {
super(context, rowList, resourceId, from, to);
mContext = context;
mProfileDao = new ProfileDAO(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row =
this.mContext.getLayoutInflater().inflate(R.layout.list_profile, null);
row.setTag(R.id.profile_title,
row.findViewById(R.id.profile_title));
row.setTag(R.id.profile_value,
row.findViewById(R.id.profile_value));
row.setTag(R.id.cb_switch, row.findViewById(R.id.cb_switch));
row.setTag(R.id.id, row.findViewById(R.id.id));
TextView profileTitle = (TextView) row.getTag(R.id.profile_title);
TextView profileValue = (TextView) row.getTag(R.id.profile_value);
cb = (CheckBox) row.getTag(R.id.cb_switch);
TextView id = (TextView) row.getTag(R.id.id);
Map<String, String> temp = (Map<String, String>) ((AdapterView<?>)
parent).getItemAtPosition(position);
cb.setChecked(isEnable(temp.get("enable")));
profileTitle.setText(temp.get("title"));
//cb.setFocusable(true);
profileValue.setText(temp.get("value"));
// String sid = (String)temp.get("id");
// id.setText(sid);
cb.setTag(position);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
Log.v("abc", "********** position is: " + cb.getTag());
// mProfileDao.updateEnable(mId, isChecked);
// Toast.makeText(mContext, getToastMessage(isChecked),
Toast.LENGTH_SHORT).show();
}
});
return (row);
}
private boolean isEnable(String value) {
boolean isEnable = false;
if (value.equals("true")) {
isEnable = true;
}
return isEnable;
}
private String getToastMessage(boolean isEnabled) {
if (isEnabled) {
return "Profile enabled";
} else {
return "Profile disabled";
}
}
}
My list_profile.xml: I'd like to pass the id to the listener in the adaper
but don't know how to do that, so i put a element in the TableRow and make
it invisible by setting the width and height to 0
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:stretchColumns="0" android:padding="5dp">
<TableRow>
<TextView xmlns:android="
http://schemas.android.com/apk/res/android"
android:id="@+id/profile_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#ffffff"
android:gravity="center_vertical"/>
<CheckBox android:id="@+id/cb_switch"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:textSize="12sp"
android:id="@+id/profile_value"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<TextView android:textSize="0sp" android:id="@+id/id"
android:layout_width="0sp"
android:layout_height="0sp"></TextView>
</TableRow>
</TableLayout>
The reference class:
String[] from = { "title", "enable", "value", "id"};
// the to array specifies the TextViews from the xml layout
// on which we want to display the values defined in the from array
int[] to = { R.id.profile_title, R.id.cb_switch, R.id.profile_value,
R.id.id };
// get a reference to the ListView
listView = (ListView) findViewById(android.R.id.list);
adapter = new ProfileAdapter(this, rowList, R.layout.list_profile,
from, to);
// nAdapter = new NewAdapter(this, pList);
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setItemsCanFocus(false);
On Wed, Apr 28, 2010 at 10:28 PM, TreKing <[email protected]> wrote:
> On Tue, Apr 27, 2010 at 6:58 PM, Jeruliu <[email protected]> wrote:
>
>> but there is way to detect the position of the item clicked???
>
>
> Going off of what you have already, you could put the incoming position in
> the checkbox's tag, then retrieve it when it's clicked.
>
>
> -------------------------------------------------------------------------------------------------
> TreKing - Chicago transit tracking app for Android-powered devices
> http://sites.google.com/site/rezmobileapps/treking
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en