开发者

Get the values from one layout to next layout?

开发者 https://www.devze.com 2023-04-06 21:30 出处:网络
I\'ve listed some items in list that extends Activity and the list are listed using Custom Adapter. My 开发者_开发百科question is, this is my xml File I\'ve added some items to this spinner. How can i

I've listed some items in list that extends Activity and the list are listed using Custom Adapter. My 开发者_开发百科question is, this is my xml File I've added some items to this spinner. How can i get the spinner values to next layout. Anyone knows then please tell me? Advance thanks.


I'm not clear on what you're actually asking here, but as a guess there are two possible things you're asking

  1. How to get the currently selected value out of the Spinner
  2. How to set the same value to a spinner in the next layout

1. Is simple enough

((Spinner)findViewById(R.id.spinner1)).getSelectedItem()

Will return the object selected by your spinner.

  1. Is slightly more complex, you'll need to determine what index in the data supplied corresponds to the result you get from getSelectedItem(), for example if you had an array of Strings then you could search through until you found the index and then set it on the new spinner.

For example:

String[] options = new String[] {"One","Two","Three","Four"};
String val = (String)((Spinner)findViewById(R.id.spinner1)).getSelectedItem();
//.......pass this to a layout/activity etc.........
for (int i=0; i<options.length; i++)
{
   if (options[i].equals(test))
   {
      ((Spinner)findViewById(R.id.spinner2).setSelection(i);
      break;
   }
}

But your best bet would be to try and explain more clearly what you're asking.


first you have to select data from spinner using

spinnerobject.setOnItemSelectedListener(
                new  AdapterView.OnItemSelectedListener() {           

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

               Spinner spinnerobject = (Spinner) findViewById(R.id.Spinner02);
              string value = (String)spinnerobj.getSelectedItem();




           }
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    // TODO Auto-generated method stub

                }
 });

then u hava to use intent for sending it to next activity..

 Use
  Intent.putExtra(..):

    intent.putExtra("keyName", "somevalue");
     This method is overloaded and takes various types as second argument: int, byte, String, various arrays..

   To get the data out use appropriate getXYZExtra(). For String this is:

   getStringExtra(String keyName)


First thing :: you can pass value from one activity to second activity not one layout to second second :: if you need to pass value from one activity to second use

first activity::

  activity.putExtra("lastpage", lastscore5); 

*here lastpage is key which unique for aplication

second activity::

Intent i1 = getIntent();
var =  i1.getIntExtra("lastpage", 1);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号