I have a ListView with CheckBox on it. and i am using Custom Adapter to populate the ListView. And I am binding the checkbox data using viewHolder
private static class PlanetArrayAdapter extends ArrayAdapter<Planet>
{
private LayoutInflater inflater;
public PlanetArrayAdapter(Context context, List<Planet> planetList)
{
super(context, R.layout.simplerow, R.id.rowTextView, planetList);
// Cache the LayoutInflate to avoid asking for a new one each time.
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// Planet to display
Planet planet = (Planet) this.getItem(position);
// The child views in each row.
CheckBox checkBox;
// Create a new row view
if (convertView == null)
{
convertView = inflater.inflate(R.layout.simplerow, null);
// Find the child views.
checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01);
// Optimization: Tag the row with it's child views, so we don't
// have to
// call findViewById() later when we reuse the row.
convertView.setTag(new PlanetViewHolder(textView, checkBox));
// If CheckBox is toggled, update the planet it is tagged with.
checkBox.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
CheckBox cb = (CheckBox) v;
Planet planet = (Planet) cb.getTag();
planet.setChecked(cb.isChecked());
}
});
}
// Reuse existing row view
else
{
// Because we use a ViewHolder, we avoid having to call
// findViewById().
PlanetViewHolder viewHolder = (PlanetViewHolder) convertView
.getTag();
checkBox = viewHolder.getCheckBox();
}
// Tag the CheckBox with the Planet it is displaying, so that we can
// access the planet in onClick() when the CheckBox is toggled.
checkBox.setTag(planet);
// Display planet data
checkBox.setChecked(planet.isChecked());
return convertView;
}
}
But the Problem is I am showing this as TabHost in vertical orientation. And one of the tab click i am showing this Listview.
So I am unable to get the click event in click event.
Or Suggest any better way to get this done.
Aucun commentaire:
Enregistrer un commentaire