如何克隆一个TextView? [英] How to clone a TextView?

查看:412
本文介绍了如何克隆一个TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个TextView,我从XML得到了。

Say I have a textview that I got from xml.

final View popupView = getLayoutInflater().inflate(R.layout.popup, null);  

final TextView tvPop = (TextView)popupView.findViewById(R.id.tvKeyPop);

不过,我想有多个 tvPop 的,我应该怎么克隆呢?

But I want to have multiple tvPop 's, how should I clone them?

感谢。

推荐答案

你可以这样做:

TextView cloned = new TextView(getApplicationContext());
cloned.setText(tvPop.getText());
cloned.setLayoutParams(tvPop.getLayoutParams());
...
cloned.setWhateverFieldYouNeedToBeCloned(tvPop().getWhateverFieldYouNeedToBeCloned());

希望有所帮助。

这篇关于如何克隆一个TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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