Sie sind auf Seite 1von 4
 

Ask

Read this post in our app!

 

1

android android-widget
android
android-widget

I want to use the android select text functionality on onclicklistener rather than onlongclicklistener. Is there any way to do this? Can anybody help me regarding this? Thanks

<a href=Sidharath Asked " id="pdf-obj-0-50" src="pdf-obj-0-50.jpg">
 

Asked

105

1

7

Feb 3 '12 at 11:57

3 Answers

 

Order By Votes

 

with xml:

2

 

android:selectAllOnFocus="true"

 
 

with code (option1):

yourEditText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //((EditText)v).selectAll(); ((EditText)v).setSelection(startValue, stopValue);

}

});

with code (option2):

 

yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){ @Override public void onFocusChange(View v, boolean hasFocus){ if (hasFocus){ //((EditText)v).selectAll(); ((EditText)v).setSelection(startValue, stopValue);

 
 

}

 

}

});

 
<a href=waqaslam Answered " id="pdf-obj-1-26" src="pdf-obj-1-26.jpg">
 

Answered

42.5k

7

92

117

Feb 3 '12 at 12:01

 

Thanks for your reply Waqas. But the thing is want to select the text randomly not the whole text. I want to use android Context menu functionality in simpler way like if i click on the text in edit text its start the point to select the text and ask to copy and paste after selecting Thats what i want to do. is there any way to do that? Thanks – Sidharath Feb 3 '12 at 12:07

Thanks for your reply Waqas. But the thing is want to select the text randomly notSidharath Feb 3 '12 at 12:07 " id="pdf-obj-1-65" src="pdf-obj-1-65.jpg">

i just updated my answer. You may provide start and end int values to make particular selection – waqaslam Feb 3 '12 at 13:08

 
 

add a comment

0

This answer gives you several options if you want to select all the text. If not then use an onclicklistener and call setSelection on your EditText. EDIT:

 
 

theEditText.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText)view; editText.setSelection(editText.getText().length()-1); // selects all the text

 

}

});

<a href=mcnicholls Answered " id="pdf-obj-2-9" src="pdf-obj-2-9.jpg">

Answered

  • 711 3 9

Feb 3 '12 at 12:03

 

Thanks for ur your answer mcnicholls. but Can you please give me detailed example for how to use the setSelection method of edittext. As i have used it by extending the EditText class. But i didnt get the idea how to use it for selecting the text on click.Thanks. – Sidharath Feb 3 '12 at 12:11

Thanks for ur your answer mcnicholls. but Can you please give me detailed example for howSidharath Feb 3 '12 at 12:11 " id="pdf-obj-2-39" src="pdf-obj-2-39.jpg">

I have added a code sample that would select all the text, but you can customise the selection by providing different for the setSelection parameters (there are a few versions of this method). – mcnicholls Feb 3 '12 at 12:20

 

add a comment

 

A totally different approach would be to try calling performLongClick from your EditText's onClick handler. This might let you use the default

0

long click functionality, but call it from your onClick.

 

theEditText.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText)view; editText.performLongClick();

 

}

 

});

<a href=mcnicholls Answered " id="pdf-obj-2-81" src="pdf-obj-2-81.jpg">

Answered

  • 711 3 9

Feb 3 '12 at 12:30

Your Answer

<a href=log in or Name Email By posting your answer, you agree to the privacy policy and terms of service . meta chat tour help blog privacy policy legal contact us full site Download the Stack Exchange Android app 2016 Stack Exchange, Inc Post Your Answer " id="pdf-obj-3-2" src="pdf-obj-3-2.jpg">

or

Name

<a href=log in or Name Email By posting your answer, you agree to the privacy policy and terms of service . meta chat tour help blog privacy policy legal contact us full site Download the Stack Exchange Android app 2016 Stack Exchange, Inc Post Your Answer " id="pdf-obj-3-10" src="pdf-obj-3-10.jpg">

Email

<a href=log in or Name Email By posting your answer, you agree to the privacy policy and terms of service . meta chat tour help blog privacy policy legal contact us full site Download the Stack Exchange Android app 2016 Stack Exchange, Inc Post Your Answer " id="pdf-obj-3-14" src="pdf-obj-3-14.jpg">

By posting your answer, you agree to the privacy policy and terms of service.

full site

2016 Stack Exchange, Inc

Post Your Answer