获取从一个布局到下一个布局的值?

发布于 2024-12-05 16:46:45 字数 190 浏览 1 评论 0原文

我在列表中列出了一些扩展 Activity 的项目,并且该列表是使用自定义适配器列出的。我的问题是,这是我的 xml 文件 我已向此微调器添加了一些项目。我怎样才能获得下一个布局的微调器值。那么有谁知道请告诉我吗?提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

屋檐 2024-12-12 16:46:45

我不清楚您在这里实际上要问什么,但猜测您可能会问两件事

  1. 如何从微调器中获取当前选定的值
  2. 如何在下一个微调器中设置相同的值布局

1.
足够简单

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

将返回微调器选择的对象。

  1. 稍微复杂一些,您需要确定提供的数据中的哪个索引对应于您从 getSelectedItem() 获得的结果,例如,如果您有一个字符串数组,那么您可以搜索直到找到索引,然后设置它在新的旋转器上。

例如:

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;
   }
}

但是你最好的选择是尝试更清楚地解释你所问的问题。

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.

凉城 2024-12-12 16:46:45

首先,您必须使用旋转器选择数据

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

                }
 });

,然后您必须使用意图将其发送到下一个活动。

 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 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)
思念绕指尖 2024-12-12 16:46:45

第一件事 :: 您可以将值从一个活动传递到第二个活动,而不是一个布局传递到第二个活动
第二个 :: 如果您需要将值从一个活动传递到第二个活动,请使用

第一个活动::

  activity.putExtra("lastpage", lastscore5); 

*这里最后一页是应用程序唯一的关键

第二个活动::

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文