android中Listview中的可滚动Edittext

时间:2015-06-10 06:09:16

标签: android scroll android-edittext

我正在处理我的一个Android项目,其中我在Listview行中显示了一个带有Edittext的Listview。问题是当我尝试滚动Edittext时,我不能这样做,因为Listview会滚动。如何在Listview中实现可滚动的Edittext。

这是我的Listview适配器代码

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    MyViewHolder mViewHolder;

    if(convertView == null) {
        convertView = inflater.inflate(R.layout.custom_deal_supplier, null);
        mViewHolder = new MyViewHolder();
        convertView.setTag(mViewHolder);
    } else {
        mViewHolder = (MyViewHolder) convertView.getTag();
    }

    mViewHolder.tvConsumerName = detail(convertView, R.id.txt_consumer_name, dealDoneListHere.get(position).getConsumerName());// Set consumer name here
    mViewHolder.edtShippingAddress=(EditText)convertView.findViewById(R.id.edt_details_shipping_address);
    mViewHolder.edtShippingAddress.setVisibility(View.VISIBLE);

// contains more than 500 characters
mViewHolder.edtShippingAddress.setText(dealDoneListHere.get(position).getShippingAddress()+"");

    return convertView;
}

这是我在xml文件中的Edittext

<com.hlink.supplementwar.view.CustomEditView
            android:id="@+id/edt_details_shipping_address"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_60_shipping"
            android:layout_margin="@dimen/dp_5"
            android:background="@drawable/deal_done_desciption"
            android:enabled="true"
            android:maxLength="500"
            android:paddingBottom="@dimen/dp_5"
            android:paddingLeft="@dimen/dp_5"
            android:paddingRight="@dimen/dp_5"
            android:scrollbars="vertical"
            android:textColor="@color/edit_text_color"
            android:textSize="@dimen/sp_13"
            android:visibility="gone"
            app:fontName="fonts/Roboto_Light.ttf" />

1 个答案:

答案 0 :(得分:1)

你可以试试这个......

mViewHolder.edtShippingAddress.setOnTouchListener(new OnTouchListener() {
    // Setting on Touch Listener for handling the touch inside ScrollView
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    // Disallow the touch request for parent scroll on touch of child view
    v.getParent().requestDisallowInterceptTouchEvent(true);
    return false;
    }
});