Created
December 22, 2015 00:18
-
-
Save agustinsivoplas/8fe2ea805573158ac1b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class MyCustomAdapter extends ArrayAdapter<Country> { | |
private ArrayList<Country> countryList; | |
public MyCustomAdapter(Context context, int textViewResourceId, | |
ArrayList<Country> countryList) { | |
super(context, textViewResourceId, countryList); | |
this.countryList = new ArrayList<Country>(); | |
this.countryList.addAll(countryList); | |
} | |
private class ViewHolder { | |
TextView code; | |
CheckBox name; | |
TextView Beschreibung, FachDatum; | |
CheckBox cbStatus; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
ViewHolder holder = null; | |
Log.v("ConvertView", String.valueOf(position)); | |
if (convertView == null) { | |
LayoutInflater vi = (LayoutInflater)getSystemService( | |
Context.LAYOUT_INFLATER_SERVICE); | |
convertView = vi.inflate(R.layout.tabitem, null); | |
holder = new ViewHolder(); | |
holder.code = (TextView) convertView.findViewById(R.id.code); | |
holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1); | |
holder.Beschreibung = (TextView) convertView.findViewById(R.id.tvBeschreibung); | |
holder.FachDatum = (TextView) convertView.findViewById(R.id.tvFachDatum); | |
holder.cbStatus = (CheckBox) convertView.findViewById(R.id.cbtabitemerledigt); | |
convertView.setTag(holder); | |
}); | |
} | |
else { | |
holder = (ViewHolder) convertView.getTag(); | |
} | |
Country country = countryList.get(position); | |
holder.cbStatus.setChecked(country.isSelected()); | |
holder.cbStatus.setText("abc"); | |
holder.Beschreibung.setText(country.getBeschreibung()); | |
holder.FachDatum.setText(country.getFachDatum()); | |
//You forget this | |
holder.cbStatus.setTag(country); | |
//move to the end | |
holder.cbStatus.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) { | |
CheckBox cb = (CheckBox) v; | |
Country country = (Country) cb.getTag(); | |
Toast.makeText(getApplicationContext(), | |
"Clicked on Checkbox: " + cb.getText() + | |
" is " + cb.isChecked(), | |
Toast.LENGTH_LONG).show(); | |
country.setSelected(cb.isChecked()); //this line is causing the crash | |
} | |
return convertView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment