简体   繁体   English

如何按照我的意图使android:textIsSelectable =“ true”工作?

[英]How do I make android:textIsSelectable=“true” work with my intent?

I'm having trouble making my textview editable - while I can make it editable, I can't pass the text to another activity via an intent . 我在使textview可编辑时遇到了麻烦-虽然我可以使其可编辑,但是我无法通过intent将文本传递给另一个活动。

In the xml of my View activity, for my textViewComment textbox, I have: 在我的View活动的xml中,对于我的textViewComment文本框,我有:

<TextView
android:id="@+id/textViewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/textboxes_for_contact"
android:textIsSelectable="true"

The text in the textbox is indeed selectable, I am able to copy it with a long press. 文本textbox确实是可选的,我可以长按复制它。

However, I have an Edit activity - when an edit button is clicked in View activity, the text in textViewComment should be passed to this Edit activity with an intent . 但是,我有一个Edit活动-在View活动中单击一个编辑按钮时, textViewComment的文本应通过intent传递给此Edit活动。 Instead, the Edittext in my EditView is empty. 而是,我的Edittext中的EditView为空。

When I remove android:textIsSelectable="true" the text is passed via the intent successfully. 当我删除android:textIsSelectable="true" ,文本将通过意图成功传递。 But... I can't edit it in the textview . 但是...我无法在textview对其进行编辑。

I also tried it programmatically with commentname.setTextIsSelectable(true); 我也用commentname.setTextIsSelectable(true);以编程方式尝试了它commentname.setTextIsSelectable(true); but this gives the same problem. 但这带来了同样的问题。

In ViewContact class I have ViewContact类中

i.putExtra("comment", commentname.getText());

In EditContact class: EditContact类中:

comment = i.getStringExtra("comment");

The xml in my EditContact class for textViewComment is: xml在我EditContacttextViewComment是:

        <EditText
            android:id="@+id/textViewComment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="textCapSentences"
            android:background="@drawable/textboxes_for_contact"
            android:maxLength="360"
            />

Any idea how I can make the text in ViewContact selectable while also passing the intent successfully? 有什么想法可以使ViewContact的文本ViewContact可选择状态,同时还可以成功传递intent吗? Is this a known issue? 这是一个已知的问题?

Replace: 更换:

 i.putExtra("comment", commentname.getText());

with: 有:

 i.putExtra("comment", commentname.getText().toString());

and see if you have better luck. 看看你是否有更好的运气。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM