[英]Application stops when i change everything in a button/textview except the Text
即時通訊使用2 Android書籍和android-studio進入材料,但現在即時通訊卡住了。 如果我嘗試更改.clickable(false)、. setenabled(false)甚至Java中的顏色,我的程序將停止。 它在實施每個頭時都運行得很流暢,但是如果我嘗試啟用(禁用第一狀態)復選框/按鈕,則當有人單擊“開始按鈕”時,我的應用程序將關閉。
注意有關Textviews和復選框的數量:Im即將簽出主要功能,並在帶有對象數組的可滾動活動中使其在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;
}
}
});
}
}
如果有人遇到此問題,這應該對您有幫助,就我而言,它可以工作。 代替
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(視圖)對話,然后選擇變量viádot。 View.VISIBLE(它是一個int)View.INVISIBLE(它也是一個int)
希望這對某人有幫助,因為我沒有解決我問題的合適方法。 Android會要求int而不是布爾值,即使構造函數要使用布爾值也是如此。 瘋狂的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.