克隆的TextView将其追加到的ViewGroup [英] Clone textview to append it to a ViewGroup
本文介绍了克隆的TextView将其追加到的ViewGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在XML定义的,以便里面的ViewGroup,在时间的onCreate我想有这些变量。
我并不想通过使用列表视图+适配器的麻烦导致其明显矫枉过正,因为我知道,因为的onCreate名单将不会改变()
这或多或少code我想有。
I have a ViewGroup defined in XML with a view inside, at onCreate time I'd like to have a variable of those.
I don't want to go through the hassle of using a listview+adapter cause its clearly overkill as I know the list won't change since onCreate()
This is more or less the code I'd like to have.
TextView mytextview = myViewGroup.findViewById(R.id.mytext);
for(String test : strings){
mytextview = mytextview.clone();
mytextview.setText(test);
myViewGroup.addView(mytextview);
}
但它不能正常工作。
But it is not working.
推荐答案
也许用吹气,并把TextView的在外部布局文件:
Maybe use an inflater, and put the textview in an external layout file:
View v = LayoutInflater.from(this).inflate(R.layout.textview_include, null);
viewGroup.addView(v);
这篇关于克隆的TextView将其追加到的ViewGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文