gpt4 book ai didi

java - 不在 Android Studio 中工作的教师应用百分比

转载 作者:行者123 更新时间:2023-12-01 10:17:04 25 4
gpt4 key购买 nike

我正在尝试向老师(我妈妈)申请计算成绩字母和可能出现的一定错误数量的百分比。当我按下第一个屏幕上的按钮后,应用程序崩溃了。我想知道是否有人可以帮助我。

import android.content.Context;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity{

int MaxInt;

private Button button;

private EditText ETmax;

private TextView TV1;
private TextView TV2;
private TextView TV3;
private TextView TV4;
private TextView TV5;
private TextView TV6;
private TextView TV7;
private TextView TV8;
private TextView TV9;
private TextView TV10;
private TextView TV11;
private TextView TV12;
private TextView TV13;
private TextView TV14;
private TextView TV15;
private TextView TV16;
private TextView TV17;
private TextView TV18;
private TextView TV19;
private TextView TV20;
private TextView TV21;
private TextView TV22;
private TextView TV23;
private TextView TV24;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstscreen);

ETmax = (EditText) findViewById(R.id.editText);

TV1 = (TextView) findViewById(R.id.textView);
TV2 = (TextView) findViewById(R.id.textView2);
TV3 = (TextView) findViewById(R.id.textView3);
TV4 = (TextView) findViewById(R.id.textView4);
TV5 = (TextView) findViewById(R.id.textView5);
TV6 = (TextView) findViewById(R.id.textView6);
TV7 = (TextView) findViewById(R.id.textView7);
TV8 = (TextView) findViewById(R.id.textView8);
TV9 = (TextView) findViewById(R.id.textView9);
TV10 = (TextView) findViewById(R.id.textView10);
TV11 = (TextView) findViewById(R.id.textView11);
TV12 = (TextView) findViewById(R.id.textView12);
TV13 = (TextView) findViewById(R.id.textView13);
TV14 = (TextView) findViewById(R.id.textView14);
TV15 = (TextView) findViewById(R.id.textView15);
TV16 = (TextView) findViewById(R.id.textView16);
TV17 = (TextView) findViewById(R.id.textView17);
TV18 = (TextView) findViewById(R.id.textView18);
TV19 = (TextView) findViewById(R.id.textView19);
TV20 = (TextView) findViewById(R.id.textView20);
TV21 = (TextView) findViewById(R.id.textView21);
TV22 = (TextView) findViewById(R.id.textView22);
TV23 = (TextView) findViewById(R.id.textView23);
TV24 = (TextView) findViewById(R.id.textView24);

//TV1-8 how many wrong
//TV9-16 percentage
//TV17-24 letter grade

button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MaxInt = Integer.parseInt(ETmax.getText().toString());
setContentView(R.layout.activity_main);
TV1.setText(MaxInt - 1);
TV2.setText(MaxInt - 2);
TV3.setText(MaxInt - 3);
TV4.setText(MaxInt - 4);
TV5.setText(MaxInt - 5);
TV6.setText(MaxInt - 6);
TV7.setText(MaxInt - 7);
TV8.setText(MaxInt - 8);
TV9.setText((int) Math.round((MaxInt - 1) / MaxInt) + "%");
TV10.setText((int) Math.round((MaxInt - 2) / MaxInt) + "%");
TV11.setText((int) Math.round((MaxInt - 3) / MaxInt) + "%");
TV12.setText((int) Math.round((MaxInt - 4) / MaxInt) + "%");
TV13.setText((int) Math.round((MaxInt - 5) / MaxInt) + "%");
TV14.setText((int) Math.round((MaxInt - 6) / MaxInt) + "%");
TV15.setText((int) Math.round((MaxInt - 7) / MaxInt) + "%");
TV16.setText((int) Math.round((MaxInt - 8) / MaxInt) + "%");


}
});

}

}

最佳答案

从 public void onClick 中删除此行

setContentView(R.layout.activity_main);

如果您只想更新 TextView 中显示的文本,那么它看起来应该适合您。如果有任何预期的布局更改,您将必须启动新的 Activity 或 fragment 。

关于java - 不在 Android Studio 中工作的教师应用百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35834849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com