我刚刚制作了这个应用程序,它在点击按钮时崩溃了...... 不知道为什么...... 到目前为止,如果选择1,则应打印1,如果选择2,则打印2,依此类推。 这是main.xml和Activity.java文件。
This is Main.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/spinnerprompt"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/Spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinnerprompt" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttontext"
android:onClick="onClick"/>
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="30dp" >
</FrameLayout>
<TextView
android:id="@+id/versetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
And Activity.java file
package arirang.today.proverbs;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class TodaysProverbsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner Spinner1 = (Spinner) findViewById(R.id.Spinner1);
ArrayAdapter adapter1 = ArrayAdapter.createFromResource(
this, R.array.datelist, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner1.setAdapter(adapter1);
}
public void onclick(View view){
Spinner Type;
String verse = "";
Type = (Spinner)findViewById(R.id.Spinner1);
if(Type.getSelectedItem().toString().equals("1")){
verse = "1";
}
if(Type.getSelectedItem().toString().equals("2")){
verse = "2";
}
if(Type.getSelectedItem().toString().equals("3")){
verse = "3";
}
if(Type.getSelectedItem().toString().equals("4")){
verse = "4";
}
if(Type.getSelectedItem().toString().equals("5")){
verse = "5";
}
if(Type.getSelectedItem().toString().equals("6")){
verse = "6";
}
if(Type.getSelectedItem().toString().equals("7")){
verse = "7";
}
if(Type.getSelectedItem().toString().equals("8")){
verse = "8";
}
if(Type.getSelectedItem().toString().equals("9")){
verse = "9";
}
if(Type.getSelectedItem().toString().equals("10")){
verse = "10";
}
if(Type.getSelectedItem().toString().equals("11")){
verse = "11";
}
if(Type.getSelectedItem().toString().equals("12")){
verse = "12";
}
if(Type.getSelectedItem().toString().equals("13")){
verse = "13";
}
if(Type.getSelectedItem().toString().equals("14")){
verse = "14";
}
if(Type.getSelectedItem().toString().equals("15")){
verse = "15";
}
if(Type.getSelectedItem().toString().equals("16")){
verse = "16";
}
if(Type.getSelectedItem().toString().equals("17")){
verse = "17";
}
if(Type.getSelectedItem().toString().equals("18")){
verse = "18";
}
if(Type.getSelectedItem().toString().equals("19")){
verse = "19";
}
if(Type.getSelectedItem().toString().equals("20")){
verse = "20";
}
if(Type.getSelectedItem().toString().equals("21")){
verse = "21";
}
if(Type.getSelectedItem().toString().equals("22")){
verse = "22";
}
if(Type.getSelectedItem().toString().equals("23")){
verse = "23";
}
if(Type.getSelectedItem().toString().equals("24")){
verse = "24";
}
if(Type.getSelectedItem().toString().equals("25")){
verse = "25";
}
if(Type.getSelectedItem().toString().equals("26")){
verse = "26";
}
if(Type.getSelectedItem().toString().equals("27")){
verse = "27";
}
if(Type.getSelectedItem().toString().equals("28")){
verse = "28";
}
if(Type.getSelectedItem().toString().equals("29")){
verse = "29";
}
if(Type.getSelectedItem().toString().equals("30")){
verse = "30";
}
if(Type.getSelectedItem().toString().equals("31")){
verse = "31";
}
TextView AfterBox = (TextView)findViewById(R.id.versetext);
AfterBox.setText(verse);
}
}
感谢您阅读,这不短...... ^^
答案 0 :(得分:0)
请更改您的活动文件的功能名称onClick(查看视图)而不是onclick(查看视图)......
函数名称区分大小写的问题....