如何避免在微调器中重复的字符串?

时间:2017-08-24 21:17:10

标签: android

我有一个微调器和一个edittext,我希望edittext在按下时获取微调器文本,但结果是文本会翻倍。

private EditText etTormenta2;
Spinner spnTormentaIni2;

String tormentaColumna1[]={"0","1","2","3","4","5","6","7","8"};

spnTormentaIni2=(Spinner)findViewById(R.id.spnTormentaIni2);


ArrayAdapter<CharSequence>adapter21=ArrayAdapter.createFromResource(this,
                R.array.combos_tormentaarena,android.R.layout.simple_spinner_item);

        spnTormentaIni2.setAdapter(adapter21);

        spnTormentaIni2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                int start =etTormenta2.getSelectionStart();
                final String str2 ="\"ColumnStart\": "+tormentaColumna1[i]+",";
                etTormenta2.getText().insert(start, str2);
            }

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

            }
        });

0 个答案:

没有答案