I have set a Array Adapter for my Spinner to display a drop-down list of Grades (A+, A, ...etc). All I need is when the user selects, A+, myApp should understand it as float value 10, so that the Value of A+ (=10) can be used in Formula that needs integer to calculate the overall grade. for eg, if user select B+, my APP should understand as 8.5, which can be used in the formula.
Basically, I want the USERS to see the Grades on the spinners but I need the Actual values of it for Calculation.
Can I make use of POSITION of Items on the Spinners? Kindly show an example how to retrieve it.
My String resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</string-array>
<string-array name="grade_list">
<item>A+</item>
<item>A</item>
<item>A-</item>
<item>B+</item>
<item>B</item>
<item>B-</item>
<item>C+</item>
<item>C</item>
<item>C-</item>
<item>D</item>
<item>E</item>
<item>U</item>
</resources>
MY JAVA CODE
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class CSEsem1 extends Activity implements OnClickListener{
Spinner cs1spin1;
Spinner cs1spin2;
Spinner cs1spin3;
Spinner cs1spin4;
Spinner cs1spin5;
Spinner cs1spin6;
Spinner cs1spin7;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.laycsesem1);
ArrayAdapter<CharSequence> grade = ArrayAdapter.createFromResource(this,
R.array.grade_list, android.R.layout.simple_spinner_item);
grade.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cs1spin1.setAdapter(sem_adapter);
cs1spin1.setOnItemSelectedListener(this);
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// Completely blank after this.
}
I need to apply the same for all the spinners. I have 7 in total in my XML file.
A method which I thought of was, Since my ITEMS on the Spinners can be converted to String, I could have used a switch (String) but Android is compiled under Java 1.5,1.6 ..and switch(String) is a featured in Java 1.7. So cannot use this.