Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android image inside single select

Tags:

android

select

I want to display images inside single select when it appears inside dialog.

alt text http://www.freeimagehosting.net/uploads/bfb1c90d61.png

How can I do it?

like image 250
d-man Avatar asked Jul 09 '10 10:07

d-man


2 Answers

Here you have working solution. Not mine, but I used described technique and it worked. Do not forget about img.setBounds(), it is necessary!

http://mgmblog.com/2010/06/10/arrayadapter-and-alertdialog-for-single-choice-items/

PS: original post does not display radiobutton, but my layout does. My single row XML layout file (animal_row.xml is missing in example) is here:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/miastorow_text"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textColor="#000"
/>
like image 151
tomash Avatar answered Nov 09 '22 22:11

tomash


You can override everything and create it from scratch. First create an xml describing the content you want. For example:

<!-- test.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:background="@color/white">
 <ImageView android:id="@+id/ImageView01"
  android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
  android:src="@drawable/facebook"></ImageView>
 <TextView android:id="@+id/TextView01" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_toRightOf="@+id/ImageView01"
  android:text="Facebook" 
            android:textSize="40sp"></TextView>
 <RadioButton android:id="@+id/RadioButton01"
  android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
  android:layout_toRightOf="@+id/TextView01"></RadioButton>
</RelativeLayout>

Then build this xml using the alert dialog. You can let the activity handle your dialog and just override the onCreateDialog like this:

@Override
protected Dialog onCreateDialog(int id) {
    View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.test, null);
    return new AlertDialog.Builder(MainActivity.this).setView(view).setTitle("Share")
                    .create();
}

You can then override onClick to store the state in your StaticPreferences files. This way you'll have complete control over all the elements in your view.

One final piece of advice, when creating the xml make sure that you create as flat a layout as possible so that the code is optimized. You can also play with the list layout to create something like this.

like image 24
Shashank Bharadwaj Avatar answered Nov 09 '22 22:11

Shashank Bharadwaj