SimpleAdapter in Android

ListView without ImageView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/title" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/artist" />
</LinearLayout>
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", "Poker Face");
map.put("artist", "Lady Gaga");
data.add(map);
map = new HashMap<String, String>();
map.put("title", "Yeah!");
map.put("artist", "Usher");
data.add(map);

SimpleAdapter simpleAdapter = new SimpleAdapter(
        this,
        data,
        R.layout.listview_without_images_view,
        new String[]{ "title", "artist" },
        new int[]{ R.id.title, R.id.artist });
ListView noImages = (ListView)findViewById(R.id.listViewNoImages);
noImages.setAdapter(simpleAdapter);

ListView with ImageView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/title" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/artist" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView" />

</LinearLayout>
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", "Poker Face");
map.put("artist", "Lady Gaga");
map.put("pic", ((Integer)R.drawable.pic).toString());
data.add(map);
map = new HashMap<String, String>();
map.put("title", "Yeah!");
map.put("artist", "Usher");
map.put("pic", ((Integer)R.drawable.pic2).toString());
data.add(map);

SimpleAdapter simpleAdapter = new SimpleAdapter(
        this,
        data,
        R.layout.listview_with_images_view,
        new String[]{ "title", "artist", "pic" },
        new int[]{ R.id.title, R.id.artist, R.id.imageView });
simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder(){

    @Override
    public boolean setViewValue(View view, Object o, String s) {
        if(view.getClass() == ImageView.class) {
            ImageView image = (ImageView)view;
            image.setImageResource(Integer.parseInt(s));
            return true;
        }
        return false;
    }
});
ListView withImages = (ListView)findViewById(R.id.listViewImages);
withImages.setAdapter(simpleAdapter);

Full code
https://github.com/randcode-generator/SimpleAdapterExample

RelativeLayout in Android

Image

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/LinearLayout1"
        android:layout_above="@+id/LinearLayout2"
        android:ems="10"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>
</RelativeLayout>

relativelayout