0

I got a problem with this code:

@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;
    }

And this is my XML:

<?xml version="1.0" encoding="utf-8"?>
<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
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >



        <Button
            android:id="@+id/btn_zoeken"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/txt_zoeken"
            android:text="@string/Zoeken" />

        <EditText
            android:id="@+id/txt_zoeken"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>
    </RelativeLayout>

</RelativeLayout>

I got this problem:
I got a list, and at the bottom of the screen their should always be an EditText and a button. But when I add this in the layout and start the app, it places the EditText and the button at every row, see Pictures:

This is how it is (bad):

How it is now (bad)

This is how it should be:

How it should be

I got in the layout a RelativeLayout in a RelativeLayout, because I hoped it would fix this problem, but it didn't.

Please be aware, I make a list in a relative layout, so I don't use a ListView.
Anyone got a solution or a suggestion how to fix this?

I hope my question is clear.

Thanks already, Bigflow

Edit 1:

@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.inflater, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        Button btn_zoeken = (Button) rowView.findViewById(R.id.button1);
        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;
    }
Bigflow
  • 3,616
  • 5
  • 29
  • 52
  • 2
    you can use `ListView's Footer` for this. This will helps you http://www.vogella.com/articles/AndroidListView/article.html#miscellaneous_headerfooter, – Mohsin Naeem Aug 14 '12 at 07:29

1 Answers1

1

Use your button(i.e. btn_zoeken) and Image(i.e. txt_zoeken) in your main.xml file as footer as Mohasin Naeem suggested.And use this android:layout_alignParentBottom="true".

And inflate your list_mobile.xml to the main.xml layout file.

So your list_mobile.xml should look like this.

 <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>

Where btn_zoeken and txt_zoeken should look at the bottom of main screen. And your inflated layout.xml should like below.

    <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>

Basically while inflating layout you need two xml files.One is your main.xml(list_mobile.xml) and another is your inflated xml

Akshay
  • 2,506
  • 4
  • 34
  • 55
  • my `main.xml` is my `list_mobile.xml`, I had to say that, sorry. I will try this solution now. – Bigflow Aug 14 '12 at 07:39
  • I still can't things to work... Please help me, I have 1 layout, tried with 2, but I just don't get it. – Bigflow Aug 14 '12 at 08:32
  • I did what you suggested, but it doesn't work, The `button` and `EditText` isn't visible (even when `list_mobile.xml` is my main). I edit the question, is what I got now (**Edit 1:**). – Bigflow Aug 14 '12 at 09:13
  • I got it, it is hard to explain why it works now. But I will say it soon. I sure needed this part too (what you wrote) +1 – Bigflow Aug 14 '12 at 09:40