android:在布局中添加水平线使其为空

问题描述

| 将其添加到布局中后,将其充气并添加到另一个视图后将返回一个空布局
  <View 
  android:layout_width=\"fill_parent\"
  android:layout_height=\"1px\" 
  android:background=\"#e0e0e0\"/>
这是我给它充气的方式
LayoutInflater vi = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View v = vi.inflate(R.layout.stoplistitem,null);
if(dt != null && stop.getDescription() != null)
    dt.setText(stop.getDescription());
if(st != null && stop.getStreet() != null)
    st.setText(stop.getStreet());
if(mt != null && stop.getMunicipal() != null)
    mt.setText(stop.getMunicipal());
if(idt != null && stop.getId() != null){
    idt.setText(stop.getId().toString());
//编辑我可以看到视图,但是没有内容     

解决方法

        通过使用
inflate(int resource,ViewGroup root,boolean attachToRoot)
将此视图附加到ViewGroup上,并且attachToRoot = true,root是要在其上膨胀的组件     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...