所以我真的很新的android編程(和java)和即時通訊嘗試做基本stuff.I跟着教程在互聯網上,但我不能設法做我的想要。我有一個帶edittext的按鈕和一個按鈕。當我點擊按鈕時,我希望spintext中的選定項和edittext中的數字能夠進入另一個文本視圖(用一個大的textview加載一個新頁面)。到目前爲止,我這樣做: (Mainactivity.java)spinner + edittext的內容到另一個頁面(textview)(android)
package com.example.spinnertest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends Activity {
Spinner s1,s2,s3,s4;
TextView txt2;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1 = (Spinner) findViewById(R.id.spinner1);
s2= (Spinner) findViewById(R.id.spinner2);
s3 = (Spinner) findViewById(R.id.spinner3);
txt2 = (TextView) findViewById(R.id.textView2);
/////////CODE PART FOR TESTING ONLY,NO LINK WITH MY QUESTION/////
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String val = s1.getSelectedItem().toString();
txt2.setText(val);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
s3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String val = s3.getSelectedItem().toString();
txt2.setText(val);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
s2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String val = s2.getSelectedItem().toString();
txt2.setText(val);
}
//////////////////END OF TESTING CODE PART///////////
// OnClickListener of Button
button.setOnClickListener(new OnClickListener() { ///theres few errors here?
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Getting values of text and spinners
//selectedDay = daySpinner.getSelectedItem().toString(); //this code doesnt fit the way I define my spinners;see below
//selectedMonth = monthSpinner.getSelectedItem().toString(); //this code doesnt fit the way I define my spinners;see below
//text = editText.getText().toString(); //this code doesnt fit the way I define my spinners;see below
// Creating an Intent to open new Activity(Screen) and sending
// the details
Intent intent = new Intent(MainActivity.this, Affichage.class);
// intent.putExtra("day", selectedDay);//this code doesnt fit the way I define my spinners;see below
//intent.putExtra("month", selectedMonth);//this code doesnt fit the way I define my spinners;see below
//intent.putExtra("text", text); //this code doesnt fit the way I define my spinners;see below
startActivity(intent);
}
});
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
}
};}}
的java Seconde系列文件活動:
package com.example.spinnertest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Spinner;
import android.widget.TextView;
public class Display extends ActionBarActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Spinner s1;
setContentView(R.layout.activity_display);
textView = (TextView) findViewById(R.id.disp);
s1 = (Spinner) findViewById(R.id.spinner1);
Intent intent = getIntent();
if(intent!=null)
{
String val = s1.getSelectedItem().toString();
textView.setText(val);
//String month = intent.getStringExtra("month"); //example from the internet;doesnt fit my code
//String text = intent.getStringExtra("text"); //example from the internet,doesnt fit my code
}
else
{
textView.setText("Intent is null");
}
}}
與TextView的第二頁
佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/afficher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
佈局是我的紡紗廠和東西定義爲:我的飛旋的
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.spinnertest.MainActivity" >
<Spinner
android:id="@+id/spinner6"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_alignLeft="@+id/spinner5"
android:layout_alignTop="@+id/editText3"
android:entries="@array/Type" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignParentLeft="true"
android:text="Description de la recette de fabrication"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:text="TextView" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:text="Fabriquer" />
<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/spin1" />
<EditText
android:id="@+id/editText3"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/spinner3"
android:layout_toRightOf="@+id/spinner3"
android:ems="10"
android:inputType="number" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner4"
android:entries="@array/spin1" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_above="@+id/editText6"
android:layout_alignLeft="@+id/textView1"
android:layout_marginBottom="29dp"
android:entries="@array/spin1" />
<EditText
android:id="@+id/editText2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_above="@+id/spinner3"
android:layout_toRightOf="@+id/spinner3"
android:ems="10"
android:inputType="number" />
<EditText
android:id="@+id/editText6"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText4"
android:layout_alignTop="@+id/spinner6"
android:ems="10"
android:inputType="number" />
<EditText
android:id="@+id/editText1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText2"
android:layout_alignTop="@+id/spinner1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText5"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_above="@+id/spinner6"
android:layout_alignParentRight="true"
android:layout_marginRight="18dp"
android:ems="10"
android:inputType="number" />
<Spinner
android:id="@+id/spinner5"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_alignTop="@+id/editText5"
android:layout_toLeftOf="@+id/editText6"
android:entries="@array/Type" />
<EditText
android:id="@+id/editText4"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText5"
android:layout_alignTop="@+id/spinner4"
android:ems="10"
android:inputType="number" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_above="@+id/spinner5"
android:layout_toRightOf="@+id/button1"
android:entries="@array/Type" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_alignParentTop="true"
android:text="Production en cours:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="@+id/spinner7"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText1"
android:layout_marginLeft="22dp"
android:entries="@array/Production" />
<EditText
android:id="@+id/editText7"
android:layout_width="50dp"
android:layout_height="25dp"
android:layout_above="@+id/editText1"
android:layout_toRightOf="@+id/spinner4"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner7"
android:layout_toRightOf="@+id/button1"
android:text="Quantité produite:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_toRightOf="@+id/textView2"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView5"
android:layout_alignBottom="@+id/textView5"
android:layout_toRightOf="@+id/textView5"
android:text="TextView" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView6"
android:layout_alignBottom="@+id/textView6"
android:layout_toRightOf="@+id/editText3"
android:text="TextView" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView7"
android:layout_alignBottom="@+id/textView7"
android:layout_toRightOf="@+id/textView7"
android:text="TextView" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner4"
android:layout_below="@+id/textView1"
android:text="TextView" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView9"
android:layout_alignBottom="@+id/textView9"
android:layout_toRightOf="@+id/textView9"
android:text="TextView" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView10"
android:layout_alignBottom="@+id/textView10"
android:layout_toRightOf="@+id/textView10"
android:text="TextView" />
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentBottom="true"
android:text="TextView" />
</RelativeLayout>
內容在array.xml定義(中值)這樣的:
<resources>
<array name="spin1">
<item>item1</item>
<item>item2</item>
<item>item3</item>
</array>
<array name="Type">
<item> A</item>
<item> B</item>
<item>c</item>
<item>d</item>
</array>
<array name="Production">
<item>motorbike</item>
</array>
</resources>
所以我想我的紡紗+的EditText走在一個TextView一個新的頁面上,我不知道該怎麼做,但我有一個很好的開始,我認爲的所選項目嗎?
謝謝