如何通过单击按钮使TextView可编辑? [英] How to make a TextView editable at the click of a button?

查看:75
本文介绍了如何通过单击按钮使TextView可编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以显示数据库中某些内容并允许用户对其进行编辑的应用程序.我有一个活动,可以在某些文本视图中显示这些详细信息.现在,屏幕底部有一个编辑"按钮.单击此按钮时,我想使textview的内容可编辑(最初是只读的),以便可以更新数据库.另外,我希望编辑"按钮变成保存"按钮.我了解我可以为此使用其他活动,但是在同一活动中有什么方法可以做到这一点?

I have an app that displays certain content from a database and lets users edit it. I have an activity that displays those details in some textviews. Now, there is an "EDIT" button at the bottom of the screen. When this button is clicked, I want to make the textview's editable (which are initially read-only) so that the database can be updated. Also, I want the "EDIT" button to turn into a "SAVE" button. I understand I can just use another activity for this, but is there any way to do this while in the same activity?

推荐答案

EditTextTextView,它可以做什么TextView可以做得更好

EditText is a TextView, what it can do TextView can do better

所以假设您有一个TextView

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:text="i am a text"
    android:textColor="#243b03" />

,并且您希望通过单击按钮可对其进行编辑;在您的onclick中添加此

and you want it to be editable by a click of a button; in your onclick add this

   TextView.setCursorVisible(true);
   TextView.setFocusableInTouchMode(true);
   TextView.setInputType(InputType.TYPE_CLASS_TEXT);
   TextView.requestFocus(); //to trigger the soft input

它们不是静态的,但是我将其设为静态,因此您知道哪个视图对象的方法是那些方法.输入文本后,关于按钮的内容,然后将文本更改为完成"或其他内容,ButtonTextView扩展而来,因此应将其视为在TextWatcher上进行了研究

they are not static, but i made it static so you know which view object's methods are those. About your Button after the text has been inputted then you change the text to "done" or whatever, Button extends from TextView so treat it as if it was-research on TextWatcher

这篇关于如何通过单击按钮使TextView可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆