当我开始活动时,需要等待片刻才能按下按钮。
我是一个初学者,我想要进步。
我认为问题出在活动的初始化上。
这是我活动的开始。其余的只是听众。
public class Questions extends AppCompatActivity{
SharedPreferences sharedPreferences;
int Question;
int Categorie;
int Reponse;
int Points_question;
int REPONSE[]= new int[5]; //tableau des reponses
int REPONSE_POINTS[][] = {{1,2,3,4},{2,3,4,5},{1,2,3,4},{2,3,4,5},{1,2,3,4},{2,3,4,5}}; //tableau fixe des points de reponses
int REPONSE_CATEGORIE[] = {1,2,2,1,2}; //Categories de chaque questions
ArrayList CATEGORIE1 = new ArrayList(); //Tableau categories 1
ArrayList CATEGORIE2 = new ArrayList(); //Tableau categorie 2
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questions);
//chercher les views
CardView cardView1 = findViewById(R.id.cardview1);
CardView cardView2 = findViewById(R.id.cardview2);
CardView cardView3 = findViewById(R.id.cardview3);
CardView cardView4 = findViewById(R.id.cardview4);
final TextView reponse1 = findViewById(R.id.reponse1);
final TextView reponse2 = findViewById(R.id.reponse2);
final TextView reponse3 = findViewById(R.id.reponse3);
final TextView reponse4 = findViewById(R.id.reponse4);
final TextView questions = findViewById(R.id.questions);
//SAVE
sharedPreferences = getPreferences(MODE_PRIVATE);
Question = sharedPreferences.getInt("num", 0);
//Mettre en forme pour la recuperation de la question
String Question_string = Integer.toString(Question);
String mnemonic_q = "q_";
String mnemonic_question = mnemonic_q + Question_string;
//Mettre en forme pour la recuperation des reponses
String mnemonic_r = "r_";
String mnemonic_reponse1 = mnemonic_r + Question_string + "1";
String mnemonic_reponse2 = mnemonic_r + Question_string + "2";
String mnemonic_reponse3 = mnemonic_r + Question_string + "3";
String mnemonic_reponse4 = mnemonic_r + Question_string + "4";
//Recuperer String
int id = getResources().getIdentifier(mnemonic_question, "string", getPackageName());
int r_1 = getResources().getIdentifier(mnemonic_reponse1, "string", getPackageName());
int r_2 = getResources().getIdentifier(mnemonic_reponse2, "string", getPackageName());
int r_3 = getResources().getIdentifier(mnemonic_reponse3, "string", getPackageName());
int r_4 = getResources().getIdentifier(mnemonic_reponse4, "string", getPackageName());
//L'ecrire
questions.setText(id);
reponse1.setText(r_1);
reponse2.setText(r_2);
reponse3.setText(r_3);
reponse4.setText(r_4);
先谢谢您!
答案 0 :(得分:0)
启动应用程序总是存在差距,但是要使应用程序加载速度更快(至少向用户显示UI),您可以将//SAVE
之后的所有内容放入另一个线程。
handler = new Handler();
Runnable r = new Runnable() {
public void run() {
//SAVE ...
}
};