opening new screen with spinner and such ?


Last Updated:

  1. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    ok so have something kinda like that i have my main activity and everything working problem is i need to be able to get this screen to show up right when i click the button i want to open this in this case button grams2mol so i want that to open the new screen i designed it in a project of its own and am trying to merge it now if anyone can help me make this work please help thanks


    void my_func115051(){
    setContentView(R.layout.calcchoice);

    grams2mol = (Button) findViewById(R.id.grams2mol);
    mole2mol = (Button) findViewById(R.id.mole2mol);
    homebutton = (Button) findViewById(R.id.home);
    homebutton.requestFocus();

    homebutton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) {my_func505();}});
    grams2mol.setOnClickListener(new Button.OnClickListener() {public void onClick(View v){my_func115052();}});
    mole2mol.setOnClickListener(new Button.OnClickListener() {public void onClick(View v){my_func11505();}});


    }
    void my_func115052(){

    class convert extends Activity implements AdapterView.OnItemSelectedListener {

    String[] element = {"actinium" ,"aluminum" ,"americium" ,"antimony" ,"argon" ,"arsenic" ,"astatine" ,"barium"
    ,"berkelium" ,"beryllium" ,"bismuth" ,"bohrium" ,"boron" ,"bromine" ,"cadmium" ,"calcium" ,"californium"
    ,"carbon" ,"cerium" ,"esium" ,"chlorine" ,"chromium" ,"cobalt" ,"copper" ,"copernicium" ,"curium"
    ,"darmstadtium" ,"dubnium" ,"dysprosium" ,"einsteinium" ,"erbium" ,"europium" ,"fermium" ,"fluorine"
    ,"francium" ,"gadolinium" ,"gallium" ,"germanium" ,"gold" ,"hafnium" ,"hassium" ,"helium" ,"holmium"
    ,"hydrogen" ,"indium" ,"iodine" ,"iridium" ,"iron" ,"krypton" ,"lanthanum" ,"lawrencium" ,"lead"
    ,"lithium" ,"lutetium" ,"magnesium" ,"manganese" ,"meitnerium" ,"mendelevium" ,"mercury" ,"molybdenum"
    ,"neodymium" ,"neon" ,"neptunium" ,"nickel" ,"niobium" ,"nitrogen" ,"nobelium" ,"osmium" ,"oxygen"
    ,"palladium" ,"phosphorus" ,"platinum" ,"plutonium" ,"polonium" ,"potassium" ,"praseodymium" ,"promethium"
    ,"protactinium" ,"radium" ,"radon" ,"rhenium" ,"rhodium" ,"roentgenium" ,"rubidium" ,"ruthenium" ,"rutherfordium"
    ,"samarium" ,"scandium" ,"seaborgium" ,"selenium" ,"silicon" ,"silver" ,"sodium" ,"strontium" ,"sulfur"
    ,"tantalum" ,"technetium" ,"tellurium" ,"terbium" ,"thallium" ,"thorium" ,"thulium" ,"tin" ,"titanium"
    ,"tungsten" ,"ununpentium" ,"ununquadium" ,"ununtrium" ,"uranium" ,"vanadium" ,"xenon" ,"ytterbium" ,"yttrium"
    ,"zinc" ,"zirconium" };

    /** Called when the activity is first created. */

    public void onCreate(Bundle icicle){
    super.onCreate(icicle);
    setContentView(R.layout.grams2moles);


    selection = (EditText) findViewById(R.id.selection);
    elementnumber = (EditText) findViewById(R.id.elementnumber);
    calculate = (Button) findViewById(R.id.calculate);
    calculate.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) {my_func1();}});

    moles5 = (TextView) findViewById(R.id.moles5);
    grams = (EditText) findViewById(R.id.grams);
    grams.requestFocus();

    Spinner spin=(Spinner)findViewById(R.id.elements);
    spin.setOnItemSelectedListener(this);

    ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, element);

    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(aa);

    }

    public void onItemSelected(AdapterView<?> parent, View v, int position, long id)
    {selection.setText(element[position]);

    if ("hydrogen".equals(element[position]))
    {elementnumber.setText("1.00794");

    }else if ("helium".equals(element[position]))
    {elementnumber.setText("4.00260");

    }else if ("lithium".equals(element[position]))
    {elementnumber.setText("6.941");

    etc.......

    }




    void my_func1(){


    Double grams2 = Double.parseDouble(grams.getText().toString());
    Double element2 = Double.parseDouble(elementnumber.getText().toString());

    {Double moles3 = (grams2 / element2);

    moles5.setText(moles3.toString());
    }


    }


    public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

    }

    }

    }
     

    Advertisement

Share This Page

Loading...