[英]Custom Android TextView with a border, and create multiple using for-loop?
因此,我想創建一個自定義的Android TextView,並在XML文件中添加邊框(而不是通過編程),並使用for循環創建其中的10個。 像這樣:
LinearLayout layout = new LinearLayout(//something, //something);
TextView tv;
String[] data = //Certain data which I'm getting
for(int i = 0; i < data.length; i++) {
tv = (TextView) findViewById(R.id.tvTest);
layout.addView(tv);
}
但這出於某種原因對我不起作用。 總結一下:
你能幫我嗎?
這是代碼片段
LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for ( ) {
View listItemView = inflater.inflate(R.layout.detaillistitem, _ListLayout, false);
_ListLayout.addView(listItemView);
TextView descriptionText = (TextView) listItemView.findViewById(R.id.Text1);
descriptionText.setText("");
}
R.layout.detaillistitem是您要充氣的物品。 _ListLayout是LinearLayout,您可以在上面添加項目。
像這樣嘗試
在外部布局文件中創建textview。
for(int i = 0; i < data.length; i++) {
View v = LayoutInflater.from(this).inflate(R.layout.textview, null);//R.layout.textview is your textview id you want to repeat..
layout.addView(v);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.