Java 将按钮/编辑文本添加到相对布局(充气)

Java 将按钮/编辑文本添加到相对布局(充气),java,android,listview,layout,layout-inflater,Java,Android,Listview,Layout,Layout Inflater,我对该代码有问题: @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = infl

我对该代码有问题:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        textView.setText(values[position]);

        // Change icon based on name
        String s = values[position];

        System.out.println("s = "+s);
        System.out.println("Results = "+name[2].toString());
        for (int i = 0; i < name.length; i ++){
            if (s.equals(name[i])) {
                imageView.setImageDrawable(loadImageFromURL("http://10.0.0.117/test/"+s+".jpg", "iOS"));
            }
        }
        return rowView;
    }
使用
main.xml
文件中的按钮(即btn_zoeken)和图像(即txt_zoeken)作为页脚,如
Mohasin Naeem
建议的那样。并使用此
android:layout\u alignParentBottom=“true”

然后将您的
列表\u mobile.xml
膨胀到
main.xml
布局文件中

因此,您的
列表\u mobile.xml
应该如下所示

 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <EditText
      android:id="@+id/editText1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_toLeftOf="@+id/button1" />

  <Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:text="Button" />

</RelativeLayout>

其中btn_zoeken和txt_zoeken应位于主屏幕底部。 您的layout.xml应该如下所示

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="5dp"
    android:contentDescription="@string/desc"
    android:src="@drawable/windowsmobile_logo" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/logo"
    android:layout_marginBottom="16dp"
    android:layout_toRightOf="@+id/logo"
    android:text="@+id/label"
    android:textSize="20dp" />
 </RelativeLayout>


基本上,在展开布局时,您需要两个xml文件。一个是
main.xml
(list_mobile.xml),另一个是展开的xml

,您可以使用
ListView的页脚进行此操作。这将帮助您,我的
main.xml
是我的
list\u mobile.xml
,我不得不这么说,对不起。我现在就试试这个解决方案。我还是不能让事情正常进行。。。请帮帮我,我有1个布局,尝试了2个,但我就是不明白。我按照你的建议做了,但不起作用,
按钮
编辑文本
不可见(即使
list\u mobile.xml
是我的主要布局)。我编辑了这个问题,就是我现在得到的(编辑1:)。我得到了,很难解释为什么它现在有效。但我很快就会说。我当然也需要这个部分(你写的)+1
 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <EditText
      android:id="@+id/editText1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_toLeftOf="@+id/button1" />

  <Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:text="Button" />

</RelativeLayout>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="5dp"
    android:contentDescription="@string/desc"
    android:src="@drawable/windowsmobile_logo" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/logo"
    android:layout_marginBottom="16dp"
    android:layout_toRightOf="@+id/logo"
    android:text="@+id/label"
    android:textSize="20dp" />
 </RelativeLayout>