I have written a program to load data from sqlite database into my spinner , so when i start an activity adapter directly loads the data into the spinner and automatically an event fires without touching anything , how i want is an empty spinner and when i select an item from spinner from dropdown then only certain event should occur.
cursor = listHelper.getAccountName(String
.valueOf(selected_item_1));
int[] to = new int[] { android.R.id.text1 };
String[] from = new String[] { DbListHelper.ACCOUNT_NAME };
final SimpleCursorAdapter adapter5 = new
SimpleCursorAdapter(
getBaseContext(),
android.R.layout.simple_list_item_1, cursor, from,
to) {
public View getView(int position, View convertView,
ViewGroup parent) {
View v = super.getView(position, convertView,
parent);
((TextView) v).setTextSize(18);
((TextView) v).setGravity(Gravity.CENTER);
((TextView) v).setTextColor(Color
.parseColor("#1C689C"));
return v;
}
public View getDropDownView(int position, View
convertView,
ViewGroup parent) {
View v = null;
if (position == 0) {
TextView tv = new TextView(getBaseContext());
tv.setHeight(0);
tv.setVisibility(View.GONE);
v = tv;
} else {
v = super.getDropDownView(position, null,
parent);
}
((TextView) v).setGravity(Gravity.CENTER);
((TextView) v).setBackgroundColor(Color.WHITE);
parent.setVerticalScrollBarEnabled(false);
return v;
}
};
adapter5.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinnerAccountName.setAdapter(adapter5);
Can anyone suggest me how to do it ? Thank You
Aucun commentaire:
Enregistrer un commentaire