views:

33

answers:

1

Hi all,

I use the following main.xml for my app.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/toplinear">
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:id="@+id/linear">
        <Button  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="Previous"
            android:id="@+id/previous"
            android:layout_weight="1"
            />
        <Button  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="Next"
            android:id="@+id/next"
            android:layout_toRightOf="@id/previous"
            android:layout_weight="1"
            />
    </LinearLayout>
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/android:list"
        android:layout_weight="10"
        />

</LinearLayout>

I want to have 2 buttons at the top, previous and next and my listview with custom adapter below it. Few days ago I had only my ListView showing, going over the buttons. Now I seem to be stuck on the other side, where my listview doesn't show while my buttons do.

My activity extends on ListActivity and uses this code to fill it with a customadapter.

ListView lv = getListView();
lv.setAdapter(new MyCustomAdapter(this, R.layout.custom_list, nameResults));

    public class MyCustomAdapter extends ArrayAdapter<String> {
        private String[] nameResults;
        private Context context;

        public MyCustomAdapter(Context context, int textViewResourceId,
                String[] names) {
            super(context, textViewResourceId, names);
            this.context = context;
            nameResults = names;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            if (row == null) {
                LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                row = inflater.inflate(R.layout.custom_list, parent, false);
            }

            TextView label = (TextView) row.findViewById(R.id.Name);
            label.setText(nameResults[position]);
            TextView descr = (TextView) row.findViewById(R.id.Description);
            descr.setText(linkedResults.get(nameResults[position]));

            return row;
        }
    }

I tried using "lv.addHeaderView(previous);" but that only gave me vague ClassCastExceptions about LayoutParams.

I think my problem is currently in my main.xml, as the Layout tab in Eclipse of it won't show the ListView either. It knows its there as it shows up in the outline tab, but the visual representation doesn't give it a red outline when I select it.

For completeness, my custom_list (aka row) layout xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffff"
>
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Name"
    android:textColor="#000000"
    android:textStyle="bold"
  />
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Description"
    android:textColor="#000000"
  />

</LinearLayout>
+1  A: 

I'm modified your main.xml a bit - added orientation and took off the layout_weight for the listview - hopefully this fixes that problem.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/toplinear">
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:id="@+id/linear">
        <Button  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="Previous"
            android:id="@+id/previous"
            android:layout_weight="1"
            />
        <Button  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="Next"
            android:id="@+id/next"
            android:layout_toRightOf="@id/previous"
            android:layout_weight="1"
            />
    </LinearLayout>
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/android:list"
        />

</LinearLayout>
xil3
That seems to have fixed it, thanks! Mind giving me an upvote for the question? Need more rep so I can upvote you as well! :D
Rvthof
You're welcome - up vote done.
xil3