即时通讯使用2个Android书籍和android-studio进入材料,但现在我卡住了。 如果我尝试更改.clickable(false),。setenabled(false)甚至是Java中的颜色,我的程序就会停止。它运行流畅,每个噱头实现,但如果我尝试启用(第一个状态禁用)复选框/按钮,当有人点击“开始按钮”时,我的应用程序关闭。
注意文本视图和复选框的数量:我即将检查mainfunctions并使用objectarray在可滚动活动中将其设置为1.0。 atm所有这些textviews只是为了让我得到一个暗示这个应用程序有多大。这是关于健康和医学考试的测验。可能有1个问题10个子问题和10个答案或1个问题,0个子问题和仅2个答案。每次考试都有大约60个问题。但是,当我禁用一个复选框或setVisebility(false)我的应用程序停止时,我无法执行此操作。
我的建议:
XML的文件:
<TextView
android:id="@+id/examchoosen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.983"
app:layout_constraintHorizontal_bias="0.92" />
<Button
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="0.982" />
<TextView
android:id="@+id/countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.016"
app:layout_constraintHorizontal_bias="0.501" />
<TextView
android:id="@+id/frage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="42dp"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.022" />
<TextView
android:id="@+id/subfrage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="84dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="@+id/subfrage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="101dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="@+id/subfrage3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="118dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/subfrage4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="135dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="@+id/subfrage5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="152dp" />
<TextView
android:id="@+id/subfrage6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="169dp" />
<TextView
android:id="@+id/subfrage7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="186dp" />
<TextView
android:id="@+id/subfrage8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="203dp" />
<TextView
android:id="@+id/subfrage9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="220dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="@+id/subfrage10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="237dp" />
<TextView
android:id="@+id/AntwortA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="273dp" />
<TextView
android:id="@+id/AntwortB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="290dp" />
<TextView
android:id="@+id/AntwortC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="307dp" />
<TextView
android:id="@+id/AntwortD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="325dp" />
<TextView
android:id="@+id/AntwortE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="342dp" />
<TextView
android:id="@+id/AntwortF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="359dp" />
<TextView
android:id="@+id/AntwortG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="376dp" />
<TextView
android:id="@+id/AntwortH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="393dp" />
<TextView
android:id="@+id/AntwortI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="410dp" />
<TextView
android:id="@+id/AntwortJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="427dp" />
<CheckBox
android:id="@+id/BoxA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="206dp" />
<CheckBox
android:id="@+id/BoxB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="189dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="172dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="155dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="137dp"
app:layout_constraintHorizontal_bias="0.113" />
<CheckBox
android:id="@+id/BoxF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="120dp"
app:layout_constraintHorizontal_bias="0.023" />
<CheckBox
android:id="@+id/BoxG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="103dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="86dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="69dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="@+id/BoxJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Java文件:
package de.isolde_richter.hp_pruefer_00;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class examenExaminer extends AppCompatActivity {
TextView frage;
TextView subfrage1;
TextView subfrage2;
TextView subfrage3;
TextView subfrage4;
TextView subfrage5;
TextView subfrage6;
TextView subfrage7;
TextView subfrage8;
TextView subfrage9;
TextView subfrage10;
TextView antwortA;
TextView antwortB;
TextView antwortC;
TextView antwortD;
TextView antwortE;
TextView antwortF;
TextView antwortG;
TextView antwortH;
TextView antwortI;
TextView antwortJ;
CheckBox BoxA;
CheckBox BoxB;
CheckBox BoxC;
CheckBox BoxD;
CheckBox BoxE;
CheckBox BoxF;
CheckBox BoxG;
CheckBox BoxH;
CheckBox BoxI;
CheckBox BoxJ;
TextView examchoosen;
Button counter;
TextView countdown;
CountDownTimer counterTimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
frage = (TextView) findViewById(R.id.frage);
subfrage1 = (TextView) findViewById(R.id.subfrage1);
subfrage2 = (TextView) findViewById(R.id.subfrage2);
subfrage3 = (TextView) findViewById(R.id.subfrage3);
subfrage4 = (TextView) findViewById(R.id.subfrage4);
subfrage5 = (TextView) findViewById(R.id.subfrage5);
subfrage6 = (TextView) findViewById(R.id.subfrage6);
subfrage7 = (TextView) findViewById(R.id.subfrage7);
subfrage8 = (TextView) findViewById(R.id.subfrage8);
subfrage9 = (TextView) findViewById(R.id.subfrage9);
subfrage10 = (TextView) findViewById(R.id.subfrage10);
antwortA=(TextView) findViewById(R.id.AntwortA);
antwortB=(TextView) findViewById(R.id.AntwortB);
antwortC=(TextView) findViewById(R.id.AntwortC);
antwortD=(TextView) findViewById(R.id.AntwortD);
antwortE=(TextView) findViewById(R.id.AntwortE);
antwortF=(TextView) findViewById(R.id.AntwortF);
antwortG=(TextView) findViewById(R.id.AntwortG);
antwortH=(TextView) findViewById(R.id.AntwortH);
antwortI=(TextView) findViewById(R.id.AntwortI);
antwortJ=(TextView) findViewById(R.id.AntwortJ);
BoxA =(CheckBox)findViewById(R.id.BoxA);
BoxB =(CheckBox)findViewById(R.id.BoxB);
BoxC =(CheckBox)findViewById(R.id.BoxC);
BoxD =(CheckBox)findViewById(R.id.BoxD);
BoxE =(CheckBox)findViewById(R.id.BoxE);
BoxF =(CheckBox)findViewById(R.id.BoxF);
BoxG =(CheckBox)findViewById(R.id.BoxG);
BoxH =(CheckBox)findViewById(R.id.BoxH);
BoxI =(CheckBox)findViewById(R.id.BoxI);
BoxJ =(CheckBox)findViewById(R.id.BoxJ);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_examen_examiner);
examchoosen = (TextView) findViewById(R.id.examchoosen);
counter = (Button) findViewById(R.id.counter);
countdown = (TextView) findViewById(R.id.countdown);
countdown.setText("(120M:00S)");
counter.setText(R.string.rdy);
counterTimer = new CountDownTimer(7200000,100) {
@Override
public void onTick(long l) {
Long totals =(l/100)/10;
Long m = totals/60;
Long s = totals%60;
//countdown.setText(""+m+"M:"+s+"S");
if(m>=10 && s >=10){
countdown.setText("("+m+"M:"+s+"S)"); //bsp 1 = (10M:10S)
} else if (m < 10 && s >=10) {
countdown.setText("(0"+m+"M:"+s+"S)"); //bsp 2 = (09M:10S)
} else if (m < 10 && s < 10) {
countdown.setText("(0"+ m+"M:0"+s+"S)"); //bsp 3 (09M:09S)
} else if (m == 0 && s<10){
countdown.setText("(00M:0"+s+"S)");//bsp 5 (00M:09S)
} else if (m >= 10 && s < 10){
countdown.setText("("+m+"M:0"+s+"S)"); //bsp 1 = (10M:09S)
}
}
@Override
public void onFinish() {
countdown.setText("(00M:00S)");
counter.setText("Fertig");
}
};
counter.setOnClickListener(new View.OnClickListener(){
private boolean startExam=false;
@Override
public void onClick(View w){
//wenn der button geklickt wird
//if the button gets clicked
if(startExam==false) {
counter.setText(R.string.next); // <- Works
counterTimer.start();
startExam = true;
}
}
});
}
}
答案 0 :(得分:0)
如果有人遇到这个问题,这对你有帮助,就我而言,它有用。 而不是
listview.setVisibility(true);
这样做:
listview.setVisibility(View.VISIBLE);
按钮,文本视图或复选框也是如此。
checkBox.setChecked(true); //that won´t work if you add dynamically in a listview or linearlayout
checkBox.toggle(); // will do the job, maybe it will work with .setChecked(!ischecked); but i had more problems with it
就我使用android-studio而言,我认识到如果你对编码中的颜色使用true / false(布尔值)或固定数字(即使设置为1和0),你的应用程序会有很多问题,不会流畅。在活动中,您需要与Parentclass(View)对话并选择变量viádot。 View.VISIBLE(这是一个int)View.INVISIBLE(也是一个int)
希望这会对某人有所帮助,因为我没有为我的问题找到适当的解决方案。 Android需要一个int而不是一个布尔值,即使构造函数需要一个布尔值。疯狂的东西。