can not select texts properly in the listview items
===

I've used this method, *android.text.Selection.setSelection(Spannable text, int index)*, to select some texts in MyEditText, a customized class extends EditText, while moving my finger. It worked perfectly in a single view, but when I apply it to multiple MyEditText items in a ListView, it didn't work properly. Here is my codes:

**MyEditText.java**

        public class MyEditText extends EditText {
    
    	public MyEditText(Context context) {
    		super(context);
    		initialize();
    	}
    
    	public MyEditText(Context context, AttributeSet attrs, int defStyle) {
    		super(context, attrs, defStyle);
    		initialize();
    	}
    
    	public MyEditText(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		initialize();
    	}
    
    	private void initialize() {
    		setBackgroundColor(Color.WHITE);
    	}
    
    	@Override
    	protected void onCreateContextMenu(ContextMenu menu) {
    		// avoid to pop out the context menu
    	}
    
    	@Override
    	public boolean getDefaultEditable() {
    		return false;
    	}
    
    	private int offset;
    
    	@Override
    	public boolean onTouchEvent(MotionEvent event) {
    		int action = event.getAction();
    		Layout layout = getLayout();
    		int line = 0;
    		switch (action) {
    		case MotionEvent.ACTION_DOWN:
    			line = layout.getLineForVertical(getScrollY() + (int) event.getY());
    			offset = layout.getOffsetForHorizontal(line, (int) event.getX());
    			Selection.setSelection(getEditableText(), offset);
    			break;
    		case MotionEvent.ACTION_MOVE:
    		case MotionEvent.ACTION_UP:
    			line = layout.getLineForVertical(getScrollY() + (int) event.getY());
    			int curOff = layout
    					.getOffsetForHorizontal(line, (int) event.getX());
    			Selection.setSelection(getEditableText(), offset, curOff);
    			break;
    		}
    		return true;
    	}
    
    }


**MyListAdapter.java**

    public class MyListAdapter extends BaseAdapter {
    
    	private ArrayList<String> entitys;
    	private Context context;
    
    	public MyListAdapter(Context context, ArrayList<String> entitys) {
    		this.context = context;
    		this.entitys = entitys;
    	}
    
    	@Override
    	public int getCount() {
    		if (entitys == null)
    			return 0;
    		return entitys.size();
    	}
    
    	@Override
    	public Object getItem(int position) {
    		if (entitys == null)
    			return null;
    		return entitys.get(position);
    	}
    
    	@Override
    	public long getItemId(int position) {
    		return position;
    	}
    
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		String entity = entitys.get(position);
    		MyEditText myTextView = (MyEditText) View.inflate(context,
    				R.layout.list_item, null);
    		myTextView.setText(entity);
    		return myTextView;
    	}
    
    }

**CopyTextTest2Activity.java**

    public class CopyTextTest2Activity extends Activity {
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		LinearLayout ll = new LinearLayout(this);
    		ListView lv = new ListView(this);
    		String values;
    
    		ArrayList<String> stringList = new ArrayList();
    		for (int i = 0; i < 10; i++) {
    			values = "" + i + "  sdfsfjskldfhsklhskdfsdhf"
    					+ "fsdfaskhfkshdfkskdfskldf"
    					+ "dfskdfhkshdfkshdkiuiouweoruweoruwoeruwoer"
    					+ "opkspdfmmbb" + "" + "dsfasdfsdfsdfsdferwre";
    			stringList.add(values);
    		}
    
    		MyListAdapter myAdapter = new MyListAdapter(this, stringList);
    		lv.setAdapter(myAdapter);
    		lv.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    
    		ll.addView(lv, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    		// lv.setEnabled(false);
    		setContentView(ll);
    
    	}
    }

**list_item.xml**

    <?xml version="1.0" encoding="utf-8"?>
    <ss.test.MyEditText xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

When you run this project, you'll find only the first item in the listview is selectable, and another weird thing is you can not select all the texts you encircled.

My opinion is that the onTouchEvent is incompatible with the scroll movement of the listview, but I could do nothing about it.

Really hope someone could help me out!

