Permalink
Browse files

Add icons to the status selection spinner.

  • Loading branch information...
Joerg Mensmann authored and ge0rg committed May 11, 2014
1 parent 2b1a784 commit eeddca2c1de37ab0002e4b810d81f91a41e40bc4
Showing with 37 additions and 21 deletions.
  1. +17 −6 res/layout/status_spinner_item.xml
  2. +20 −15 src/org/yaxim/androidclient/dialogs/ChangeStatusDialog.java
@@ -1,7 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="@android:style/TextAppearance.Widget.TextView.SpinnerItem"
android:padding="15dip" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dip">
<ImageView
android:id="@+id/status_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/status_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_marginLeft="10dip" />
</LinearLayout>
@@ -18,6 +18,7 @@
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AutoCompleteTextView;
@@ -54,8 +55,7 @@ public int compare(StatusMode object1, StatusMode object2) {
mStatus = (Spinner) group.findViewById(R.id.statusview_spinner);
StatusModeAdapter mStatusAdapter;
mStatusAdapter = new StatusModeAdapter(context, android.R.layout.simple_spinner_item, modes);
mStatusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mStatusAdapter = new StatusModeAdapter(context, R.layout.status_spinner_item, modes);
mStatus.setAdapter(mStatusAdapter);
for (int i = 0; i < modes.size(); i++) {
@@ -99,25 +99,30 @@ public StatusModeAdapter(Context context, int textViewResourceId,
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
TextView textView = (TextView) super.getDropDownView(position,
convertView, parent);
textView.setText(getItem(position).getTextId());
return textView;
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent, true);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView,
parent);
textView.setText(getItem(position).getTextId());
textView.setPadding(0, 0, 0, 0);
return textView;
return getCustomView(position, convertView, parent, false);
}
public View getCustomView(int position, View convertView, ViewGroup parent, boolean padding) {
LayoutInflater inflater = getLayoutInflater();
View spinner = inflater.inflate(R.layout.status_spinner_item, parent, false);
TextView text = (TextView) spinner.findViewById(R.id.status_text);
text.setText(getItem(position).getTextId());
ImageView icon = (ImageView) spinner.findViewById(R.id.status_icon);
icon.setImageResource(getItem(position).getDrawableId());
if (!padding)
spinner.setPadding(0, 0, 0, 0);
return spinner;
}
}
}

0 comments on commit eeddca2

Please sign in to comment.