- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用以下方法将字符串解析为其他 Activity :
Intent i=new Intent(this,Solve.class);
String thepoint = mshow2.getText().toString();
i.putExtra("thepoint", gpapointstring);
startActivity(i);
我使用以下方式收到它:
Bundle gpadata =getIntent().getExtras();
String fgpapoint=gpadata.getString("thepoint");
TextView mgpaView =(TextView) findViewById(R.id.gpa_point);
mgpaView.setText(""+ fgpapoint);
Mainactivity.java:
public class MainActivity extends Activity {
private Spinner mcourse9gr, mcourse9un, mcourse8gr, mcourse8un, mcourse7gr, mcourse7un, mcourse6gr, mcourse6un, mcourse5gr, mcourse5un, mcourse4gr, mcourse4un, mcourse3gr, mcourse3un, mcourse2gr, mcourse2un, mcourse1gr, mcourse1un;
public TextView mshow; public TextView mshow1; public TextView mshow2;
public double unit1; public double coursegrade1; public double grade1; public double unit2; public double coursegrade2; public double grade3; public double grade2; public double unit3; public double coursegrade3; public double unit4; public double grade4; public double coursegrade4; public double unit5; public double grade5; public double unit6; public double coursegrade5; public double grade6; public double coursegrade6; public double unit7; public double grade7; public double coursegrade7; public double unit8; public double unit9; public double grade8; public double grade9;
public double coursegrade8; public double coursegrade9; public double totalunit; public double gpapoint; public double totalcoursegrade; public String gpapointstring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addItemsOnSpinner();
OnItemSelectedListener();
mshow = (TextView) findViewById(R.id.show);
mshow1 = (TextView) findViewById(R.id.show1);
mshow2 = (TextView) findViewById(R.id.show2);
}
public void addItemsOnSpinner() {
mcourse1gr = (Spinner) findViewById(R.id.course1gr);
mcourse2gr = (Spinner) findViewById(R.id.course2gr);
mcourse3gr = (Spinner) findViewById(R.id.course3gr);
mcourse4gr = (Spinner) findViewById(R.id.course4gr);
mcourse5gr = (Spinner) findViewById(R.id.course5gr);
mcourse6gr = (Spinner) findViewById(R.id.course6gr);
mcourse7gr = (Spinner) findViewById(R.id.course7gr);
mcourse8gr = (Spinner) findViewById(R.id.course8gr);
mcourse9gr = (Spinner) findViewById(R.id.course9gr);
mcourse1un = (Spinner) findViewById(R.id.course1un);
mcourse2un = (Spinner) findViewById(R.id.course2un);
mcourse3un = (Spinner) findViewById(R.id.course3un);
mcourse4un = (Spinner) findViewById(R.id.course4un);
mcourse5un = (Spinner) findViewById(R.id.course5un);
mcourse6un = (Spinner) findViewById(R.id.course6un);
mcourse7un = (Spinner) findViewById(R.id.course7un);
mcourse8un = (Spinner) findViewById(R.id.course8un);
mcourse9un = (Spinner) findViewById(R.id.course9un);
Integer[] items = new Integer[]{0, 1, 2, 3, 4, 5};
ArrayAdapter<Integer> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, items);
mcourse1un.setAdapter(adapter);
mcourse2un.setAdapter(adapter);
mcourse3un.setAdapter(adapter);
mcourse4un.setAdapter(adapter);
mcourse5un.setAdapter(adapter);
mcourse6un.setAdapter(adapter);
mcourse7un.setAdapter(adapter);
mcourse8un.setAdapter(adapter);
mcourse9un.setAdapter(adapter);
String[] itemsgr = new String[]{"F", "E", "D", "C", "B", "A"};
ArrayAdapter<String> adaptergr = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsgr);
mcourse1gr.setAdapter(adaptergr);
mcourse2gr.setAdapter(adaptergr);
mcourse3gr.setAdapter(adaptergr);
mcourse4gr.setAdapter(adaptergr);
mcourse5gr.setAdapter(adaptergr);
mcourse6gr.setAdapter(adaptergr);
mcourse7gr.setAdapter(adaptergr);
mcourse8gr.setAdapter(adaptergr);
mcourse9gr.setAdapter(adaptergr);
}
public void OnItemSelectedListener() {
mcourse1un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit1 = mcourse1un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse1gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade1 = mcourse1gr.getSelectedItemPosition();
coursegrade1 = grade1 * unit1;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse2un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit2 = mcourse2un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse2gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade2 = mcourse2gr.getSelectedItemPosition();
coursegrade2 = grade2 * unit2;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse3un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit3 = mcourse3un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse3gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade3 = mcourse3gr.getSelectedItemPosition();
coursegrade3 = grade3 * unit3;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse4un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit4 = mcourse4un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse4gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade4 = mcourse4gr.getSelectedItemPosition();
coursegrade4 = grade4 * unit4;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse5un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit5 = mcourse5un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse5gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade5 = mcourse5gr.getSelectedItemPosition();
coursegrade5 = grade5 * unit5;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse6un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit6 = mcourse6un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse6gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade6 = mcourse6gr.getSelectedItemPosition();
coursegrade6 = grade6 * unit6;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse7un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit7 = mcourse7un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse7gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade7 = mcourse7gr.getSelectedItemPosition();
coursegrade7 = grade7 * unit7;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse8un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit8 = mcourse8un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse8gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade8 = mcourse8gr.getSelectedItemPosition();
coursegrade8 = grade8 * unit8;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse9un.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
unit9 = mcourse9un.getSelectedItemPosition();
updateunit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mcourse9gr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
grade9 = mcourse9gr.getSelectedItemPosition();
coursegrade9 = grade9 * unit9;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void onClick(View view) {
updategrade1();
updategrade2();
updategrade3();
updategrade4();
updategrade5();
updategrade6();
updategrade7();
updategrade8();
updategrade9();
updatetotalgrade();
setGpapoint();
Intent i=new Intent(this,Solve.class);
String thepoint = mshow2.getText().toString();
i.putExtra("thepoint", gpapointstring);
startActivity(i);
}
public void updategrade1(){
coursegrade1 = grade1 * unit1;
}
public void updategrade2() {
coursegrade2 = grade2 * unit2;
}
public void updategrade3() {
coursegrade3 = grade3 * unit3;
}
public void updategrade4() {
coursegrade4 = grade4 * unit4;
}
public void updategrade5() {
coursegrade5 = grade5 * unit5;
}
public void updategrade6() {
coursegrade6 = grade6 * unit6;
}
public void updategrade7() {
coursegrade7 = grade7 * unit7;
}
public void updategrade8() {
coursegrade8 = grade8 * unit8;
}
public void updategrade9() {
coursegrade9 = grade9 * unit9;
}
public double updatetotalgrade(){
double totalcoursegrade = coursegrade1 + coursegrade2 + coursegrade3 + coursegrade4 + coursegrade5 + coursegrade6 + coursegrade7 + coursegrade8 + coursegrade9;
mshow.setText(""+ totalcoursegrade);
return totalcoursegrade;
}
public double updateunit(){
double totalunit = unit1 + unit2 + unit3 + unit4 + unit5 + unit6 + unit7 + unit8 + unit9;
// i uesd this to make sure i am getting a value an not null
mshow1.setText("" + totalunit);
return totalunit;
}
public double setGpapoint() {
double totalunit = unit1 + unit2 + unit3 + unit4 + unit5 + unit6 + unit7 + unit8 + unit9;
double totalcoursegrade = coursegrade1 + coursegrade2 + coursegrade3 + coursegrade4 + coursegrade5 + coursegrade6 + coursegrade7 + coursegrade8 + coursegrade9;
double gpapoint = (totalcoursegrade/totalunit);
String gpapointstring =String.format("your GPA: %.2f",gpapoint);
// i uesd this to make sure i am getting a value an not null
mshow2.setText(String.format("your GPA: %.2f",gpapoint));
return gpapoint;
}
}
解决.java:
public class Solve extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inputgrade);
addListenerOnButton();
Bundle gpadata = getIntent().getExtras();
String fgpapoint = gpadata.getString("thepoint");
TextView mgpaView = (TextView) findViewById(R.id.gpa_point);
mgpaView.setText("" + fgpapoint);
}
public void addListenerOnButton() {
final Context context =
this;
button = (Button) findViewById(R.id.home);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent =
new
Intent(context, MainActivity.class);
startActivity(intent);
}
});
}
}
最佳答案
您需要使用实际具有值的字符串引用
String thepoint = mshow2.getText().toString();
i.putExtra("thepoint", thepoint);
或
gpapointstring= mshow2.getText().toString();
i.putExtra("thepoint", gpapointstring);
第二:如果某个值已经是字符串,则不需要 ""+
连接(额外的开销),所以只需这样做
mgpaView.setText(fgpapoint);
第三:不需要额外的支架
final Context context = this;
只需使用
Intent intent = new Intent(Solve.this, MainActivity.class);
关于java - 从另一个 Activity 获取字符串值后,我的 TextView 中不断出现空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46811110/
如果这不是一个错误,那就是另一个错误。如果不是那样的话,那就是别的东西了。我觉得我的项目已经改变了很多,现在只是试图解决代码签名问题,结果一切都搞砸了。我严格按照说明进行操作,但出现错误,例如当前的“
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。 对于我的一个项目,我有一个如下的 makefile: CC=g++ CFLAGS=-O3 `libpng-co
我有大约 10 个 div,它们必须不断翻转,每个 div 延迟 3 秒 这个 codrops 链接的最后一个效果是我正在寻找的,但无需单击 div http://tympanus.net/Devel
我如何使用 jQuery 持续运行 PHP 脚本并每秒获取响应,以及将鼠标上的少量数据发送到同一脚本? 我真的必须添加一些随机扩展才能让这么简单的计时器工作吗? 最佳答案 To iterate is
JBoss 4.x EJB 3.0 我见过如下代码(大大简化): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPO
使用 PHPStorm,我试图忽略每次尝试进行 git 提交时 pop 的 workspace.xml。 我的 .gitignore 看起来像: /.idea/ .idea/workspace.xml
我是一名优秀的程序员,十分优秀!