我需要打開EditText
的drawableRight
點擊電話的聯繫簿。 drawableRight
上的點擊事件工作正常但問題是,當我點擊/觸摸EditText
上的任何地方時,它也是執行點擊事件並打開聯繫人列表。EditText的drawableRight上的Click事件無法正常工作?
我採取幫助從這裏Please check this link.
上drawableRight
管理單擊事件我不想打開聯繫人列表當我點擊EditText
,我只是想打開它,當我點擊drawableRight
(圖像)。那麼如何解決這個問題呢?
這裏是我的代碼:
EditText mobile_number;
mobile_number = (EditText)view.findViewById(R.id.mobile_number1);
mobile_number.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if(event.getAction()==MotionEvent.ACTION_UP){
if(event.getRawX()>=(mobile_number.getRight()-mobile_number.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()));
{
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent,PICK_CONTACT);
return true;
}
}
return true;
}
});
這裏是我的佈局代碼:
<LinearLayout
android:layout_width="fill_parent"
android:id="@+id/linearlayout_two1"
android:layout_below="@+id/linearlayout_one1"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:orientation="vertical"
>
<EditText
android:layout_width="300dp"
android:hint="Enter Your Mobile Number"
android:textSize="15sp"
android:id="@+id/mobile_number1"
android:paddingLeft="30dp"
android:layout_height="wrap_content"
android:drawableRight="@drawable/editbox_icon"
/>
</LinearLayout>
添加到佈局1是編輯文本,另一個是圖像。然後在圖像中設置ontuchlistner \ – Destro
將最後一個'返回true;'更改爲'return false;',然後再次測試。 – NamNH
@John將它改爲false不起作用,任何事情........我已經試過了。 –