1
我一直在努力有兩個edittext字段和兩個spinners的活動。在EditText字段中輸入的文本不會顯示在我生成的祝詞中,即使在spinners中完成了選擇。我究竟做錯了什麼 ?字符串不顯示在android吐司
package com.goswami.pntgo.notifierdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.*;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class LoginScreen extends Activity {
String Course = null;
String Semester = null;
String univRollNo = null;
String name = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_screen);
final EditText tvname = (EditText) findViewById(R.id.name);
final EditText tvunivrn = (EditText) findViewById(R.id.univ_roll_no);
name = tvname.getText().toString();
univRollNo = tvunivrn.getText().toString();
Spinner course = (Spinner)findViewById(R.id.course);
Spinner semester = (Spinner)findViewById(R.id.semester);
ArrayAdapter cadapter = ArrayAdapter.createFromResource(this,R.array.courses,R.layout.courses);
ArrayAdapter sadapter = ArrayAdapter.createFromResource(this,R.array.semesters,R.layout.courses);
course.setAdapter(cadapter);
semester.setAdapter(sadapter);
course.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id){
Course = parent.getItemAtPosition(pos).toString();
}
});
semester.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Semester = parent.getItemAtPosition(position).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Button login = (Button)findViewById(R.id.button);
login.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Toast.makeText(LoginScreen.this,(name+" Roll No:"+univRollNo+"\n"+Course+" "+Semester),Toast.LENGTH_LONG).show();
}
});
}
}