you have write confusing code.
you insert tag to text2 on:
holder.text2.setTag(1);
then next line of that use:
int position12 = (Integer)holder.text2.getTag();
so every time position12
is equal to 1.
next thing is using of j
instead of position.
you need change back your visibility too like following code because ListView's recycling
if(j<8){
holder.text2.setVisibility(View.INVISIBLE);
holder.check.setVisibility(View.VISIBLE);
holder.check.setX(-150);
}else{
holder.text2.setVisibility(View.VISIBLE);
holder.check.setVisibility(View.INVISIBLE);
}
and as you have one layout why you Override getViewTypeCount
and getItemViewType
?
please remove following line from getView method,
holder.text2.getText();
and
Log.v("DDD", holder.text2.getText().toString());
Your Problem
your problem is on:
private class OnItemClickListener implements OnClickListener{
private int mPosition;
OnItemClickListener(int position){
mPosition = position;
}
@Override
public void onClick(View arg0) {
CustomListViewAndroidExample sct = (CustomListViewAndroidExample)activity;
sct.onItemClick(mPosition); <--- problem is here
}
}
I don't know what you want exactly but you can do this.
1- change:
vi.setOnClickListener(new OnItemClickListener(position));
to
vi.setOnClickListener(this);
2- add following line to getView method:
holder.text.setTag(position);
3- add following code to onClick method:
@Override
public void onClick(View v) {
TextView tv = (TextView)v.findViewById(R.id.textView1);
int pos = (Integer)tv.getTag();
Log.d("position of clicked item is", ""+pos);
}
4- change
if(j<8)
to
if( position <8)