2012-03-06 4 views
0

안녕하세요, 모두내 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.... 
+0

레이아웃 코드를 공유 할 수 있습니까? – Soham

+0

예, 레이아웃을 업로드했습니다 – a7omiton

+0

버튼을 클릭 할 때 onClick 내부에 앱이 있는지 보려면 onClick 내부에서 빠르게 로그 할 수 있습니까? – Soham

답변

1

이것은보기가 당신이 textViews를 쓰는 중에 업데이트되지 않기 때문입니다. 다른

+0

err 어떻게하면됩니까? invalidate()를 호출하여? 미안 해요 초보자입니다 – a7omiton

+0

이러한 모든 활동을 하나의 레이아웃 자체에서 올바르게 수행하고 있습니까? 나는 버튼이 클릭 된 지점과 텍스트 뷰가 표시되어야하는 지점을 의미합니까? –

+0

예. 모든 레이아웃이 한 레이아웃에서 발생합니다. 버튼을 클릭하면 동일한 화면에 텍스트보기 안에 문자열이 표시되어야합니다. – a7omiton

1

OR를 다시 그립니다하여보기를 새로 고침 시도하거나 볼 수있는 몇 가지 의도를 통과 쓰기 부분이 작동하는지 여부를 통해 UR 관심이 사용 "TOAST"방법,

여기
Toast.makeText(LoginpageActivity.this, "Write your text here to display", Toast.LENGTH_LONG).show(); 

, "LoginpageActivity"의 경우 현재 클래스 이름

+1

고마워요.이 방법으로 다른 문제 영역을 볼 수 있습니다. 귀하의 의견을 보내 주셔서 감사합니다. – a7omiton

관련 문제