Java 将此代码改编为我的代码?(安卓)

Java 将此代码改编为我的代码?(安卓),java,android,android-layout,textview,android-spinner,Java,Android,Android Layout,Textview,Android Spinner,因此,基本上我有6个微调器,6个edittext和一个按钮,当我单击按钮时,我希望微调器+编辑文本中的所有选定元素进入文本视图(显示)。我有这个java代码来实现这一点,但代码不适合我的实际代码: import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class Affichage extends ActionBarActivity { TextView

因此,基本上我有6个微调器,6个edittext和一个按钮,当我单击按钮时,我希望微调器+编辑文本中的所有选定元素进入文本视图(显示)。我有这个java代码来实现这一点,但代码不适合我的实际代码:

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Affichage extends ActionBarActivity {

TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_affichage);

    textView = (TextView) findViewById(R.id.afficher);

    Intent intent = getIntent();
    if(intent!=null)
    {
        String day = intent.getStringExtra("day");
        String month = intent.getStringExtra("month");
        String text = intent.getStringExtra("text");

        textView.setText(day + "\n" + month + "\n" + text);

    }
    else
    {
        textView.setText("Intent is null");
    }
}}
在此代码中,微调器的定义如下:

String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday" };
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
但我在xml文件(mainactivity.xml)中定义微调器,例如:

<Spinner
        android:id="@+id/spinner3"
        android:layout_width="130dp"
        android:layout_height="35dp"
        android:layout_above="@+id/button1"
        android:layout_alignLeft="@+id/spinner2"
        android:entries="@array/Products" />

我以这种方式填充微调器,在一个数组中,在xml文件中:

<array name="Products">
<item>p1</item>
<item>p2</item>
<item>p3</item>
</array> 

p1
p2
p3
那么,如何使第一个代码适应我定义微调器的方式呢

谢谢您

根据说明,微调器的设置如下:

String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday" };
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
Spinner-Spinner=(Spinner)findViewById(R.id.Spinner);
//使用字符串数组和默认微调器布局创建ArrayAdapter
ArrayAdapter=ArrayAdapter.createFromResource(此,
R.array.planets_数组,android.R.layout.simple_微调器_项);
//指定显示选项列表时要使用的布局
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
//将适配器应用于微调器
旋转器。设置适配器(适配器);
在onCreate()中我看不到任何微调器。 假设数组xml位于资源文件夹中并由资源标记包装,它应该是

Spinner spinner = (Spinner) findViewById(R.id.spinner3);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.Products, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Spinner-Spinner=(Spinner)findviewbyd(R.id.spinner3);
ArrayAdapter=ArrayAdapter.createFromResource(此,
R.array.Products、android.R.layout.simple\u spinner\u item);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
旋转器。设置适配器(适配器);

要处理用户选择,您需要设置onItemSelectedListener。文档还证明了这一点。

我对android(初学者)真的很陌生,我不明白你的意思;那两个布局是什么?我有一个用于微调器+编辑文本的布局和一个用于大文本视图的布局,用于将微调器和编辑文本中的元素放入其中
simple\u微调器项目和simple\u微调器项目和simple\u下拉项目
是定义微调器及其下拉项目外观的标准布局文件。检查文档,上面有描述。当你说你有两个布局时,我想你指的是你的活动布局文件,带有文本编辑和微调器项?