[英]Scroll edittext in listview
我有一個ListView
,它的項目包括EditText
。 每個edittext都有多行,但是行的高度是有限的。 因此,我需要在edittext中滾動。 我搜索了許多解決方案,但沒有成功。
在這種情況下,touchEvent由ListView處理,並且不會傳遞給子級。 您可以重寫onInterceptTouchEvent並從中返回false,然后將touch事件傳遞給子級(EditText)。
public class myListView extends ListView {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
return false;
}
}
注意:如果將touchEvent傳遞給child,則將無法滾動ListView。 因此,根據您的要求,您必須決定何時從onInterceptTouchEvent返回false。
參考: http : //developer.android.com/training/gestures/viewgroup.html
使用此自定義列表視圖,我遇到了使用以下代碼解決的相同問題。
public class Mylistview extends ListView{
public Mylistview(Context context) {
super(context);
}
public Mylistview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Mylistview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false; // redirect MotionEvents to ourself
case MotionEvent.ACTION_CANCEL:
Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
return false;
default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
return true;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.