Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paste option for edittext

Tags:

java

android

I have an edittext and I would like to paste some text in it. I can copy the text from some web page but I am not able to paste the text in my edittext control.How can I enable my edittext to paste some text.Here is my main.xml for edittext ;

enter code here

<EditText 
   android:id="@+id/enter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight= "2"
android:scrollbars="vertical"
android:textColor="@color/black"
/>

Thanks

like image 818
artist Avatar asked May 15 '12 03:05

artist


People also ask

How do I use clipboard manager on Android?

Open the messaging app on your Android, and press the + symbol to the left of the text field. Select the keyboard icon. When the keyboard appears, select the > symbol at the top. Here, you can tap the clipboard icon to open the Android clipboard.


2 Answers

This is on Android 4.4.2 Samsung S4;

Documentation for TextView says that:

To allow users to copy some or all of the TextView's value and paste it somewhere else, set the XML attribute android:textIsSelectable to "true" or call setTextIsSelectable(true). The textIsSelectable flag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in copy/paste controls.

There is also another Textview attribure called android:cursorVisible which determines if the system should be invoked about the copy/paste callbacks.

By default I believe both of these are true and selection/copy/paste mechanics are already enabled. I could not change that behaviour by using android:textIsSelectable="false" but if I set android:cursorVisible="false" initially you can't paste anything inside the EditText. Only after you type something in, cursor and selection behaviour becomes enabled again. Maybe this should be handled inside the code rather than in the layout xmls, or it might be related to android:inputType which also did not make a difference for me.

So try setting android:cursorVisible="true" in your EditText's layout xml if paste is not enabled by default.

like image 76
Kerem Avatar answered Sep 19 '22 21:09

Kerem


According to your problem if you copied some data any where in your system and you want to paste it in some specific variable, like Edit TextBox, Textview etc, then this code will surely help you.

 ClipboardManager clipMan = (ClipboardManager)getSystemService(v.getContext().CLIPBOARD_SERVICE);
 myEdtTxt.setText(clipMan.getText());

Note:- here the clipMan object will store the data whenever copied process take place and we will return that data from that object and will set it,

like image 45
Pir Fahim Shah Avatar answered Sep 22 '22 21:09

Pir Fahim Shah