我是 Android 编程的新手。我只想知道如何在 Android 中将文本插入到视图中?或者如果不可能,我如何在视图中插入一个字符串?我想要做的是有一个带有布局和文本的视图。
final LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tx = new TextView(this);
View vw;
Boolean hasRow = false;
ListView lv = findViewById(R.id.lv);
tx.setText("asdasd");
if(hasRow){
vw = layoutInflater.inflate(R.layout.row, null);
} else {
vw = layoutInflater.inflate(R.layout.row2, null);
}
lv.addFooterView(vw, tx.getText(), true);
lv.setAdapter(adapter);
我的代码允许我插入一个带有布局但没有文本的视图。请帮忙。谢谢!
如果要将文本设置TextView
为ListView
. 使用TextView
inlated 布局(row 或 row2)。
if (hasRow){
vw = layoutInflater.inflate(R.layout.row, null);
} else {
vw = layoutInflater.inflate(R.layout.row2, null);
}
TextView footTextView = vw.findViewById(R.id.txt_your_footer);
footTextView.setText("asdasd");
lv.addFooterView(vw);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句