• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps [Beginner] Layout Problem

MCiD

Lurker
Hi all,
I have a quit simple problem:
I would like to have an TextView element above a List.
So I got the list working using the Tutorials. And of course TextView is now problem using LinearLayout and make it a child of it. :)

But how can I have a LinearLayout and a TextView and a List as child? :confused: Is there any approach? If there is an example I would be very happy, but I searched quit long, so I don't think there is one already available.

Also If there is information about how to combine to views I would be very happy.

Thank you.

MCiD
 
Hi,

I managed it, to have a TextView and a ListView within a LinearLayout. But every time I want to add an Element I get the Resources$NotFoundException. :mad:

This is my layout (remote.xml):
Code:
<?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" >
    <Button android:id="@+id/add"
            ...some Button />              
    <TextView android:id="@+id/currentDirectory"
              ...some Text/>
    <ListView android:id="@+id/list"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content" />
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/element"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="16sp" >
        </TextView>
</LinearLayout>
The ListView should be the list, and the TextView with id element should be the elements of the list.

Here follows the java code:
Code:
        setContentView(R.layout.remote);
        System.out.println("Done: setContentView(R.layout.remote);");
        ListView list = (ListView)findViewById(R.id.list);        
        adapter = new ArrayAdapter<String>(this, R.id.element, R.id.list);
        list.setAdapter(adapter);
        directoryField = (TextView)findViewById(R.id.currentDirectory);
Is set in the click event of the button to add an Element:
Code:
    public void onClick(View v) {
        adapter.add("hallo");        
    }
Every time this code is executed I get:
D/AndroidRuntime(12539): Shutting down VM
W/dalvikvm(12539): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(12539): FATAL EXCEPTION: main
E/AndroidRuntime(12539): android.content.res.Resources$NotFoundException: Resource ID #0x7f05000a type #0x12 is not valid

Please, if anybody as an Idea what the problem could be I am glad.

Thank you,

MCiD
 
Back
Top Bottom