开发者

switching a TextView to an EditText

开发者 https://www.devze.com 2023-01-19 16:29 出处:网络
The need is to make a title (TextView) tappable to edit it(EditText)... I\'m using the trick to have 1 TextView and 1 EditText next to each other in my xml layout, and then I play with .setVisibility

The need is to make a title (TextView) tappable to edit it(EditText)...

I'm using the trick to have 1 TextView and 1 EditText next to each other in my xml layout, and then I play with .setVisibility(View.INVISIBLE/VISIBLE) to visually switch them.

Since TextView and EditText are pretty clos开发者_如何学运维e, is that possible to effectively switch one for the other? Or does anyone have a better trick I couldn't find?

Thanks


Why not have your TextView, then on click hide it. Then use Java to create a EditText in its place.


From my point of view, there are two ways you could accomplish this.

Since EditText derives from TextView, you could just make the EditText not editable(android:editable=false) -- and then change that attribute programatically when you want to.

The second method is to use the invisible/visible switching of the EditText and TextView.

I don't think there is a big difference between the two performance wise. Its a designer decision.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号