Нет проблем ... Я открыт для любого предложения, чтобы заставить его работать ... Код, который я получил, находится по ссылке
лько дней я ищу решение для кликабельных элементов в listView.
Сначала я наткнулся на это:developer.android.com/resources/articles/touch-mode.html и обнаружил, что он не имеет "нормального" поведения onListItemClick ().
Потом я наткнулся наэтот код: http://www.androidsnippets.org/snippets/125/
// LINE 296-321
@Override
protected ViewHolder createHolder(View v) {
// createHolder will be called only as long, as the ListView is not filled
// entirely. That is, where we gain our performance:
// We use the relatively costly findViewById() methods and
// bind the view's reference to the holder objects.
TextView text = (TextView) v.findViewById(R.id.listitem_text);
ImageView icon = (ImageView) v.findViewById(R.id.listitem_icon);
ViewHolder mvh = new MyViewHolder(text, icon);
// Additionally, we make some icons clickable
// Mind, that item becomes clickable, when adding a click listener (see API)
// so, it is not necessary to use the android:clickable attribute in XML
icon.setOnClickListener(new ClickableListAdapter.OnClickListener(mvh) {
public void onClick(View v, ViewHolder viewHolder) {
// we toggle the enabled state and also switch the icon
MyViewHolder mvh = (MyViewHolder) viewHolder;
MyData mo = (MyData) mvh.data;
mo.enable = !mo.enable; // toggle
ImageView icon = (ImageView) v;
icon.setImageBitmap(
mo.enable ? ClickableListItemActivity.this.mIconEnabled
: ClickableListItemActivity.this.mIconDisabled);
}
});
Во время отладки я заметил параметрПросмотр v этоTextView а не "нормальный" вид а то конечно
TextView text = (TextView) v.findViewById(R.id.listitem_text);
returnesзначение NULL и я получаю исключение NullPointerException ...
Есть идеи почему? И как я могу решить это?
Заранее спасибо! :)