Dear all,
I've tried my every effort to fight with this issue for two days but
no any luck.
What I want to do is: Display a list view with 3 elements: title,
subtitle and a checkbox. It will be ideal that the event handler only
fires when user click on the CheckBox but not the list item.
I start with the CheckedListView first but it seems this component
didn't provide a good interface to populate two properties as one
component.
Then I was think if it's possible to directly use the checkbox and
catch the onlick event?
I then created a customized View Adapter:
public class ProfileAdapter extends SimpleAdapter {
.......
@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);
// this map was filled in my list activity class which
contains key: title, value, enable and id
Map<String, String> temp = (Map<String, String>)
((AdapterView<?>) parent).getItemAtPosition(position);
profileTitle.setText(temp.get("title"));
profileValue.setText(temp.get("value"));
profileValue.setText(temp.get("value"));
String sid = (String)temp.get("id");
id.setText(sid);
cb.setChecked(isEnable(temp.get("enable")));
cb.setFocusable(false);
cb.setOnCheckedChangeListener(new
OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean
isChecked) {
Log.v("test", "********** sid is: " + sid);
//mProfileDao.updateEnable(mId, isChecked);
//Toast.makeText(mContext,
getToastMessage(isChecked),
Toast.LENGTH_SHORT).show();
}
});
I tried to use onCheckedChanged to capture the CheckBox click event
but there is way to detect the position of the item clicked??? I doubt
if is this the right place or right way to do it.
Please kindly help... thanks millions
--
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