将微调器上所选项的字符与一组字符进行比较

时间:2016-07-28 14:49:17

标签: android android-studio character android-spinner

我正在尝试将微调器上所选项目的字符与另一个字符进行比较。我将在明天29/07/2016捍卫我的最后一年项目,而我仍然没有完成我的编码。

 public void addListenerToSelect_PHS(){
     Select_DayOfTheWeek = (Spinner)
         findViewById(R.id.DayOfTheWeek);
     Select_DayOfTheWeek.setOnItemSelectedListener(newAdapterView.OnItemSelectedListener() {
     @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String itemSelectedInSpinner = parent.getSelectedItem().toString();
            if (itemSelectedInSpinner .equals("Computer Science")){
                Toast.makeText(ActivityMain.this, "You are from Computer Science", Toast.LENGTH_SHORT).show();
                Select_DayOfTheWeek = (Spinner)
                        findViewById(R.id.DayOfTheWeek);
                ArrayAdapter<CharSequence> Select_DayOfTheWeekAdapter =
                        ArrayAdapter.createFromResource(getApplicationContext(),R.array.ComptWeek,
                                android.R.layout.simple_spinner_item);
                Select_DayOfTheWeekAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                Select_DayOfTheWeek.setAdapter(Select_DayOfTheWeekAdapter);
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
}

1 个答案:

答案 0 :(得分:1)

String selectedItem=Select_DayOfTheWeek.getSelectedItem().toString();
if(selectedItem.equals("Computer Science")){
 Toast.makeText(ActivityMain.this, "You are from Computer Science", Toast.LENGTH_SHORT).show();
}