Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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 微调器项导致活动(Android Studio)_Java_Android - Fatal编程技术网

Java 微调器项导致活动(Android Studio)

Java 微调器项导致活动(Android Studio),java,android,Java,Android,我几个月前开始编程,stackoverflow一直是解决我问题的好工具。所以我的代码越来越好,但现在我又需要你的帮助 程序:在我的应用程序中,你可以从微调器中选择项目,然后转到下一页,依此类推。在得到结果之前,您必须从多个微调器中进行选择 一些代码预览(代码可以工作,但我现在不得不做更多的广告,我不知道如何 package com.sio.fmf; import android.content.Context; import android.content.Intent; import and

我几个月前开始编程,stackoverflow一直是解决我问题的好工具。所以我的代码越来越好,但现在我又需要你的帮助

程序:在我的应用程序中,你可以从微调器中选择项目,然后转到下一页,依此类推。在得到结果之前,您必须从多个微调器中进行选择

一些代码预览(代码可以工作,但我现在不得不做更多的广告,我不知道如何

package com.sio.fmf;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Button;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.TextView;

public class Koerperform extends AppCompatActivity {
  String[] koerperform = {" ", "spindel- oder torpedoförmig", "langgestreckt", "hochrückig", "schlangenförmig", "welsartig", "grundelartig"};

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.koerperform);

    Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
    mySpinner.setAdapter(new MyCustomAdapter(Koerperform.this,R.layout.spinner_layout, koerperform));
  }

  public void onClick(View v){}
  public class MyCustomAdapter extends ArrayAdapter<String> {
    public MyCustomAdapter(Context context, int textViewResourceId, String[] objects) {
      super(context, textViewResourceId, objects);
    }

    private Button getSwtitchact;
    {
      final Button switchact = (Button) findViewById(R.id.button3);
      switchact.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          Intent act = new Intent(view.getContext(), Maulstellung.class);
          startActivity(act);
        }
      });
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
      return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater = getLayoutInflater();
      View row = inflater.inflate(R.layout.spinner_layout, parent, false);
      TextView label = (TextView) row.findViewById(R.id.koerper);
      label.setText(koerperform[position]);

      if (position == 0) {
        label.setTextColor(0xFFF00000);
      }
      return row;
    }
  }
}
<pre>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".Koerperform"
    android:background="#023738">




    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:id="@+id/imageView1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/header" />

    <ImageView
        android:layout_width="400dp"
        android:layout_height="100dp"
        android:id="@+id/imageView5"
        android:background="@drawable/frageeins"
        android:layout_below="@+id/space4"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="120dp"
        android:id="@+id/imageView6"
        android:background="@drawable/fischeins"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/imageView5" />

    <Spinner
        android:id="@+id/spinner"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView6"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:clickable="false"
        android:contextClickable="false"
        />

    <Button
        android:layout_width="220dp"
        android:layout_height="60dp"
        android:id="@+id/button3"
        android:layout_marginTop="69dp"
        android:background="@drawable/costum_button_weiter_gehts"
        android:layout_below="@+id/imageView6"
        android:layout_centerHorizontal="true" />

    <Space
        android:layout_width="30dp"
        android:layout_height="20dp"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:id="@+id/space4" />

</RelativeLayout>
package com.sio.fmf;
导入android.content.Context;
导入android.content.Intent;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.view.view;
导入android.widget.ArrayAdapter;
导入android.widget.Spinner;
导入android.widget.Button;
导入android.view.ViewGroup;
导入android.view.LayoutInflater;
导入android.widget.TextView;
公共类KoerperPerform扩展了AppCompative活动{
字符串[]koerperperform={“,”spindel-order Orderaförmig“,”Langestreckt“,”hochrückig“,”schlangenförmig“,”welsartig“,”Grundelatig“};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.koerperPerform);
微调器mySpinner=(微调器)findViewById(R.id.Spinner);
setAdapter(新的MyCustomAdapter(koerperPerform.this,R.layout.spinner_layout,koerperPerform));
}
公共void onClick(视图v){}
公共类MyCustomAdapter扩展了ArrayAdapter{
公共MyCustomAdapter(上下文上下文,int textViewResourceId,字符串[]对象){
超级(上下文、textViewResourceId、对象);
}
私有按钮getSwtitchact;
{
最终按钮开关动作=(按钮)findViewById(R.id.button3);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Intent act=newintent(view.getContext(),Maulstellung.class);
星触觉(act);
}
});
}
@凌驾
公共视图getDropDownView(int位置、视图转换视图、视图组父视图){
返回getCustomView(位置、转换视图、父级);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
返回getCustomView(位置、转换视图、父级);
}
公共视图getCustomView(int位置、视图转换视图、视图组父视图){
LayoutInflater充气机=getLayoutInflater();
视图行=充气器。充气(R.layout.spinner\u布局,父级,false);
TextView标签=(TextView)row.findViewById(R.id.koerper);
label.setText(koerperperform[位置]);
如果(位置==0){
label.setTextColor(0xFFF00000);
}
返回行;
}
}
}
因此,在应用程序的这种状态下,您可以从微调器中选择字符串,然后如果按Botton 3,它将变为class
Maulstellung

我的问题:我希望当选择字符串“a”时,它在按下按钮3后进入xy页,当选择字符串“b”时,它在按下按钮3后进入xyz页,…,依此类推每个字符串


希望你能帮助我,并为我糟糕的英语道歉

也许这个布局文件有帮助


我将这样做:

不确定这是你需要的

在全局中声明
String selectedValue
Spinner mySpinner
(在
String[]koerperperform
行后添加)

移除mySpinner旁边的
微调器

  private Button getSwtitchact;
    {
      final Button switchact = (Button) findViewById(R.id.button3);
      switchact.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          selectedValue=mySpinner.getSelectedItem().toString(); // here you get the selected items from spinner
          if(selectedValue.equals("a"))
          {
          Intent act = new Intent(view.getContext(), xy.class);
          startActivity(act);
          }
          else if(selectedValue.equals("B"))
          {
          Intent act = new Intent(view.getContext(), xyZ.class);
          startActivity(act);
          }
          else
         {
           ......
         }
        }
      });
    }
在getSwtitchact内部,更改为


你有多少个微调器?嗨,John,每个classif字符串a上只选择一个,转到xy…Maulstellung for?Maulstellung是第二个类,在那里你也有一个微调器,可以引导你更进一步。但正如上面的代码中所述,Maulstellung只是有一个周期来测试应用程序。在未来,它应该取决于你选择的字符串选择调用一个特殊类。所以我的问题可能是:我如何定义微调器项“a”指向类xy,微调器项“b”指向类xyz(只是示例)。我不知道Android Studio是如何工作的。它需要一个侦听器,还是我应该像“如果按下开关,则切换到Java类”?对不起,我是noob;)谢谢你的帮助,约翰,你的意思是
字符串a
spindel-order Orderaförmig
字符串b
langgestreckt
等等?嘿,约翰,看起来像我想要的。非常感谢。当我再次回家时,我将尝试代码。“声明字符串selectedValue”在全局中是什么意思Odeclare
String selectedValue
下面的
String[]koerperperform
。刚刚尝试了一下,但是仍然有一个小问题我无法解决代码行“selectedValue=mySpinner.getSelectedITem()等等”有一个错误mySpinner无法解决并且代码中是红色的?原因是什么?抱歉,如果我只是问一些愚蠢的问题,请将
mySpinner
旁边的
Spinner
移到
String selectedValue
之后,然后声明
Spinner mySpinner
。谢谢John Joe,你让我开心了
  private Button getSwtitchact;
    {
      final Button switchact = (Button) findViewById(R.id.button3);
      switchact.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          selectedValue=mySpinner.getSelectedItem().toString(); // here you get the selected items from spinner
          if(selectedValue.equals("a"))
          {
          Intent act = new Intent(view.getContext(), xy.class);
          startActivity(act);
          }
          else if(selectedValue.equals("B"))
          {
          Intent act = new Intent(view.getContext(), xyZ.class);
          startActivity(act);
          }
          else
         {
           ......
         }
        }
      });
    }