I used a custom spinnercolor adapter spinnerin an android application. The fall is working fine. But as soon as I select a color (element) from the counter, it is not selected. Also, I do not need to show the selected item as it is selected. I only want to highlight the selected color without displaying it.
Below is the code for my CustomSpinnerAdapter:
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView rowView=null;
if(convertView == null){
convertView=inflater.inflate(R.layout.spinner_layout, null);
}
rowView=(TextView) convertView.findViewById(R.id.spinnerColorview);
rowView.setBackgroundColor(Color.parseColor(itemList.get(position)));
return convertView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView rowView=null;
if(convertView == null){
convertView=inflater.inflate(R.layout.spinner_layout, null);
}
rowView=(TextView) convertView.findViewById(R.id.spinnerColorview);
rowView.setBackgroundColor(Color.parseColor(itemList.get(position)));
return convertView;
}
EDIT: ADDITIONAL INFORMATION
My dropdown in spinner is not selectable. When I clicked on the counter, it displays a list. But when I select one item from this list, nothing happens. I cannot identify the selected item.
When I print the position inside the method getView(int position, View convertView, ViewGroup parent), it prints all the identifiers of the elements.
, , . spinner_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="true"
android:orientation="horizontal"
android:paddingLeft="40dp"
tools:context=".MainActivity" >
<TextView
android:id="@+id/spinnerColorview"
android:layout_width="200px"
android:layout_height="50px"
android:clickable="true"
android:gravity="center_vertical"
>
</TextView>
</LinearLayout>