How can I modify the text color of the selected item on a Spinner in an Android Honeycomb application?
EDIT: I have a Spinner layout which i\'m inflating. Is it possible
I used this code for ListView adaper:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
EntSaleDocumentDetails entSaleDocumentDetails = getItem(position);
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflator.inflate(R.layout.myLayout,
null);
} else {
rowView = (View) convertView;
}
TextView myTv= (TextView) rowView
.findViewById(R.id.tvCode);
myTv.setTextSize(16);
//....
// set selected item
LinearLayout ActiveItem = (LinearLayout) rowView;
if (position == selectedItem)
{
ActiveItem
.setBackgroundResource(R.drawable.background_dark_blue);
}
else
{
ActiveItem
.setBackgroundResource(R.drawable.border02);
}
//....
}
public void setSelectedItem(int position) {
selectedItem = position;
}
your custom layout:
<?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:layout_gravity="right"
android:background="@drawable/border02"
android:gravity="right"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/back_color_selector03"
android:gravity="right" >
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:gravity="right"
android:text="TextView" >
</TextView>
<TextView
android:id="@+id/tvCode"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="@+id/llProductDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/back_color_selector_blue_simple" >
<ImageButton
android:id="@+id/btnProductDetails"
android:layout_width="40dip"
android:layout_height="40dip"
android:src="@drawable/prd_details" />
<TableLayout
android:id="@+id/tblProductDetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="@+id/tvQty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvLblQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvStockQty"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvLblStockQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="@+id/tvMablagh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvLblMablagh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvFee"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
<TextView
android:id="@+id/tvLblFee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="20dip"
android:text="TextView"
android:textColor="@color/darkText" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
and in activity:
@Override
protected void onListItemClick(ListView parent, View view, int position,
long id) {
super.onListItemClick(parent, view, position, id);
adapter.setSelectedItem(position);
myListView.invalidateViews();
}