views:

27

answers:

0

This is my program.When I run this program it doesn't show any error .But no output on the emulator.I cant Debug this program also.any one solve my problem.

package com.aspiresys.spinnerbutton;

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast;

public class spinbutton extends Activity { Button button; EditText edit; ArrayAdapter adapter; Spinner spinner; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

    button = (Button)this.findViewById(R.id.button);
    edit = (EditText)this.findViewById(R.id.edit);  
    spinner = (Spinner)this.findViewById(R.id.spinner);

    adapter = ArrayAdapter.createFromResource(
            this, R.array.planets_array, android.R.layout.simple_spinner_item);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(adapter);

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String temp = edit.getText().toString();

            adapter.add(temp);
            adapter.notifyDataSetChanged();
            spinner.setAdapter(adapter);

        }
    });


    spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int pos, long id) {

            Toast.makeText(parent.getContext(), "The planet is " +
                      parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();

        }

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

        }});
}

}