안녕하세요, 모두내 TextView를 onClickListener 버튼으로 볼 수 없습니다.
내 텍스트 뷰가 내 앱에 표시되지 않는 이유를 알고 싶습니다. 단추의 onClick 메서드 안에 선언 했으므로 버튼을 한 번 클릭하면 팝업됩니다. 기본적으로 사용자가 정답을 입력하면 텍스트보기에 올바르게 표시되며, 그렇지 않으면 잘못 입력 된 "입력"버튼 유형입니다.
public void Easy12(){
Random rand = new Random();
int a = (int) rand.nextInt(100)+1;
int b = (int) rand.nextInt(100)+1;
final TextView tv = (TextView) findViewById(R.id.question_label);
String aString = Integer.toString(a);
String bString = Integer.toString(b);
String display = aString + " + " + bString + " =";
tv.setText(display);
final int c = a + b;
final Button buttonhash = (Button) findViewById(R.id.keypad_hash);
buttonhash.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
final EditText edittext = (EditText) findViewById(R.id.USERentry);
if(edittext.getText().equals(c)){
final TextView answerLabel = (TextView) findViewById(R.id.rightwrong_label);
answerLabel.setText(R.string.answer_correct);
answerLabel.setTextColor(R.color.correct_color);
}
else
{
final TextView answerLabel = (TextView) findViewById(R.id.rightwrong_label);
answerLabel.setText(R.string.answer_wrong);
answerLabel.setTextColor(R.color.wrong_color);
}
}
});
}
대괄호 때문에 인식하지 못하기 때문에 같은 텍스트 뷰를 호출하는 별도의 텍스트 뷰를 만들어야했습니다. 이 메소드는 내 Game 클래스의 일부로 표현식을 표시하고 화면의 버튼을 눌러 사용자의 대답이 올바른지 여부를 확인합니다. 아무도 잘못 알고 있다면 공유하십시오. 고마워요
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/question_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/rightwrong_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/USERentry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:textColor="@color/user_txt_color"/>
<TableLayout....
레이아웃 코드를 공유 할 수 있습니까? – Soham
예, 레이아웃을 업로드했습니다 – a7omiton
버튼을 클릭 할 때 onClick 내부에 앱이 있는지 보려면 onClick 내부에서 빠르게 로그 할 수 있습니까? – Soham