Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何显示带有链接数据的两个微调器?_Java_Android_Xml_Xml Parsing_Android Spinner - Fatal编程技术网

Java 如何显示带有链接数据的两个微调器?

Java 如何显示带有链接数据的两个微调器?,java,android,xml,xml-parsing,android-spinner,Java,Android,Xml,Xml Parsing,Android Spinner,我想在微调器-1的基础上填充微调器-2 例如,如果我选择牛顿,则微调器-2将仅显示力和苹果,而不显示其他值,如果我选择Hiiii仅显示ds,则应在微调器-2上填充。这只是我在下图中展示的一个示例(原始应用程序中的所有值都是动态的)。如果在spinner-1中选择了任何值,则应在spinner-2中填充带有确定标记的值 UPDATE-3 MainActivity.java NodeList nodeList = doc.getElementsByTagName("a:AAAAA");

我想在微调器-1的基础上填充微调器-2

例如,如果我选择牛顿,则微调器-2将仅显示苹果,而不显示其他值,如果我选择Hiiii仅显示ds,则应在微调器-2上填充。这只是我在下图中展示的一个示例(原始应用程序中的所有值都是动态的)。如果在spinner-1中选择了任何值,则应在spinner-2中填充带有确定标记的值

UPDATE-3 MainActivity.java

NodeList nodeList = doc.getElementsByTagName("a:AAAAA");
            for (int i = 0; i < nodeList.getLength(); i++) {
                Element el = (Element) nodeList.item(i);
                // get the a:W value
                String awValue = el.getElementsByTagName("a:W").item(0).getTextContent();
                // add the above value in our map  as key if it isn't present in the map, this key will 
                // have a list associated with it in which ALL the values for a:R will be stored, if 
                // the awValue key is present then you just add the new a:R value to its list 
                if (!values.containsKey(awValue)) {
                    values.put(awValue, new ArrayList<String>());

                }
                // also add the value pointed by a:R to the list associated with a:W
                String arValue = el.getElementsByTagName("a:R").item(0).getTextContent();
                values.get(awValue).add(arValue);

               // Log.d("ADebugTag", "Value: " + arValue);
            }
             Log.d("ADebugTag", "Value: " +  values);
因此,如果在喷丝头1中选择了菠萝蜜,则-卷心菜、凯撒、阿蒙德应在喷丝头2中种植

我从MainActivity.java的UPDATE-3下面的代码中获得的上述日志

NodeList nodeList = doc.getElementsByTagName("a:AAAAA");
            for (int i = 0; i < nodeList.getLength(); i++) {
                Element el = (Element) nodeList.item(i);
                // get the a:W value
                String awValue = el.getElementsByTagName("a:W").item(0).getTextContent();
                // add the above value in our map  as key if it isn't present in the map, this key will 
                // have a list associated with it in which ALL the values for a:R will be stored, if 
                // the awValue key is present then you just add the new a:R value to its list 
                if (!values.containsKey(awValue)) {
                    values.put(awValue, new ArrayList<String>());

                }
                // also add the value pointed by a:R to the list associated with a:W
                String arValue = el.getElementsByTagName("a:R").item(0).getTextContent();
                values.get(awValue).add(arValue);

               // Log.d("ADebugTag", "Value: " + arValue);
            }
             Log.d("ADebugTag", "Value: " +  values);
NodeList NodeList=doc.getElementsByTagName(“a:AAAAA”);
for(int i=0;i

我应该如何将键值传递给spinner,如果spinner键值发生更改,则spinner2中的相应值应发生更改

第一次只需填充spinner1即可。为此,更改parse方法以返回主标记列表(
title1
),并将它们设置为spinner

然后在spinner1上使用
setOnItemSelectedListener
,并在其中解析XML以查找与所选项目相关的项目,并基于此填充spinner2。您可以使用所选项目的
位置
获取该项目。为此,请编写另一个方法(或使用相同的方法,使用
if
条件,表示这不是主标记),从spinner1获取所选项目作为输入并返回子项目。然后将此列表添加到spinner2

最后,你必须有这样的东西:

   spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position) 
       {           
           title2=parse(spinner1.get(position)
          //set title2 to spinner2
       });
spinner1.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图、整型位置)
{           
title2=parse(spinner1.get(位置)
//将标题2设置为喷丝头2
});

xml数据来自URL xml Dom parserwant,用于将哈希值传递给微调器,如果微调器数据单击以进行更改,则在微调器2中填充该值,即Log.d(“ADebugTag”,“value:+arValue”);…所有值正确分组的位置…因此,如果微调器值被更改,则相应的组将显示在微调器2中。我改进了答案,并解释了如何操作。唯一需要做的是更改解析方法,以获取字符串并基于输入返回列表。您可以使用相同的方法,只需使用“如果”不同纺纱机的条件不同。
   spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position) 
       {           
           title2=parse(spinner1.get(position)
          //set title2 to spinner2
       });