T
T
TaTIk942016-09-08 22:52:40
Java
TaTIk94, 2016-09-08 22:52:40

Can't merge texts?

I can not insert the selected spinners into the message.
In the message, the places of the selected items are written nullnull
here is an example code, I will also accept the answer for combining spinners into 1 itemclistener

public class MainActivity extends Activity {
    private Button buttonSend;
    private EditText textTo;
    private EditText textSubject;
    private EditText textMessage;
    String selected;
    String selected1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);




       // Получаем экземпляр элемента Spinner
        final Spinner spinner = (Spinner)findViewById(R.id.spinner);
        final Spinner spinner1 = (Spinner)findViewById(R.id.spinner1);

// Настраиваем адаптер
        ArrayAdapter<?> adapter =
                ArrayAdapter.createFromResource(this, R.array.animals, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        ArrayAdapter<?> adapter1 =
                ArrayAdapter.createFromResource(this, R.array.catlist, android.R.layout.simple_spinner_item);
        adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// Вызываем адаптер
        spinner.setSelection(0);
        spinner.setAdapter(adapter);
        spinner1.setAdapter(adapter1);

        buttonSend = (Button) findViewById(R.id.buttonSend);
        textTo = (EditText) findViewById(R.id.editTextTo);
        textSubject = (EditText) findViewById(R.id.editTextSubject);
        textMessage = (EditText) findViewById(R.id.editTextMessage);


        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent,
                                       View itemSelected, int selectedItemPosition, long selectedId) {

                String[] choose = getResources().getStringArray(R.array.animals);
                selected = choose[selectedItemPosition];
            }
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent,
                                       View itemSelected, int selectedItemPosition, long selectedId) {

                String[] choose1 = getResources().getStringArray(R.array.catlist);
                selected1 = choose1[selectedItemPosition];
            }
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        textMessage.setText(selected + selected1);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question