Inside a list view I have on each row a text which is truncated because it is too long. So I set the setMovementMethod() on the textView in order to make it scrollable. But now the ListView cannot be clicked. How can I solve this problem?
Below is the getView() method from the adapter.
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.nameLabel = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
holder.nameLabel.setMovementMethod(ScrollingMovementMethod.getInstance());
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
I managed to solve this issue by myself after all. I implemented the OnTouchListener inside the adapter and set it on the text view. The logic for touch event is: I check if the touch event is a tap or a swipe. If it is a swipe the swipe/scroll will be performed and if it a tap I call the method I use for the listView's click event.
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsScrolling = false;
mDownX = motionEvent.getX();
break;
case MotionEvent.ACTION_MOVE:
float deltaX = mDownX - motionEvent.getX();
if ((Math.abs(deltaX) > mSlop)) { // swipe detected
mIsScrolling = true;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsScrolling) {
openNewScreen(v); // this method is used for click listener of the ListView
}
break;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With