Android 초보자, 버튼 텍스트가 변경되지 않음

차드

나는 스스로 안드로이드를 가르치려고 노력하고 있는데 완전히 갇혀있다. 기본 텍스트가 "button"인 9 개의 버튼 배열과 기본 텍스트가 "Hello World!"인 TextView가 있습니다.

I can get the TextView's text to change to Lorem Ipsum, 
but I can't get the button array text to change to "Btn something"

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    rv = new RemoteViews(getPackageName(), R.layout.activity_main);
    int i = 0;
    bArr[i++] = (Button) findViewById(R.id.button1);
    bArr[i++] = (Button) findViewById(R.id.button2);
    bArr[i++] = (Button) findViewById(R.id.button3);
    bArr[i++] = (Button) findViewById(R.id.button4);
    bArr[i++] = (Button) findViewById(R.id.button5);
    bArr[i++] = (Button) findViewById(R.id.button6);
    bArr[i++] = (Button) findViewById(R.id.button7);
    bArr[i++] = (Button) findViewById(R.id.button8);
    bArr[i] = (Button) findViewById(R.id.button9);

    for(i = 0; i < 0; i++) {
        bArr[i].setText("Btn " + i); //Doesn't Work
        rv.setTextViewText(bArr[i].getId(), "Btn " + i); // Doesn't work
        bArr[i].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Btn pressed", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    ((TextView)findViewById(R.id.text1)).setText("Lorem Ipsum"); // Works
}

그리고 XML 파일 :

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="edu.csub.cs.cenri3390.MainActivity"
tools:showIn="@layout/activity_main"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">

<Button
    android:id="@+id/button7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="@+id/button4"
    android:layout_marginTop="11dp"
    app:layout_constraintTop_toBottomOf="@+id/button4"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="@+id/button4" />
<!-- 8 more buttons.../>
<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintBottom_creator="1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    android:layout_marginBottom="91dp"
    app:layout_constraintLeft_toLeftOf="parent" />

  </android.support.constraint.ConstraintLayout>

버튼이 고장 났지만 상관 없으면 좋겠어요. 어쨌든 올바른 위치에 배치됩니다.

제임스

for 루프가 여기에서 부적절하게 인스턴스화되어 실행되지 않습니다. 물론 결코 사실이 아닌 i=0만큼 오래 실행되도록 루프를 설정 하고 지시했습니다 i<0.

for(i = 0; i < 0; i++) {
    bArr[i].setText("Btn " + i); //Doesn't Work
    rv.setTextViewText(bArr[i].getId(), "Btn " + i); // Doesn't work
    bArr[i].setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Btn pressed", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

for(i=0;i<9;i++)항상 9 개의 버튼이 있다는 것을 알고 있다면 그렇게 할 수 있습니다 .

또한 사용하는 버튼을 반복 하고 개별적으로 액세스하는 데 layout.getChildCount()사용할 수있는 팁 layout.getChildAt(i)입니다. 그래서하는 대신

rv = new RemoteViews(getPackageName(), R.layout.activity_main);
int i = 0;
bArr[i++] = (Button) findViewById(R.id.button1);
...
bArr[i] = (Button) findViewById(R.id.button9);

당신은 할 수 있습니다

for(i=0;i<layout.getChildCount();i++) {
    // Do something
    layout.getChildAt(i).setText('something');
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

부트 스트랩 버튼 텍스트가 보이지 않음

분류에서Dev

버튼 텍스트가 변경되지 않음

분류에서Dev

텍스트 상자에 텍스트가 표시되지 않음 (라디오 버튼)

분류에서Dev

Android-버튼 텍스트 중심이 작동하지 않음

분류에서Dev

xml에서 Android 버튼 배경색이 변경되지 않음

분류에서Dev

Onclick 버튼 초보자의 Android 앱이 실행되고 있지 않습니다.

분류에서Dev

React.js 버튼 클래스가 변경되지 않음

분류에서Dev

CardView 버튼과 텍스트가 정렬되지 않음

분류에서Dev

버튼 텍스트가 표시되지 않음

분류에서Dev

Flutter-버튼 내부의 텍스트가 변경되지 않습니다.

분류에서Dev

대화 상자에서 버튼을 눌러도 텍스트가 업데이트되지 않음

분류에서Dev

버튼 클릭시 텍스트 상자 값이 업데이트되지 않음

분류에서Dev

버튼 텍스트 변경이 작동하지 않음 iOS

분류에서Dev

버튼 클릭시 Android TextView가 업데이트되지 않음

분류에서Dev

Android 목록보기 항목 클릭 텍스트 변경 버튼

분류에서Dev

텍스트 상자와 버튼이 제대로 정렬되지 않음

분류에서Dev

초보자 Android 프로그래머, 버튼이 작동하지 않습니까?

분류에서Dev

Android : 대화 상자에서 버튼의 텍스트 변경

분류에서Dev

Android : 대화 상자에서 버튼의 텍스트 변경

분류에서Dev

사용자가 홈 화면으로 이동 한 후 버튼 클릭시 이미지가 변경되지 않음

분류에서Dev

버튼 클릭시 반응 상태가 변경되지 않음

분류에서Dev

버튼을 눌러도 상태가 변경되지 않음

분류에서Dev

버튼을 눌러도 상태가 변경되지 않음

분류에서Dev

선택 버튼을 통한 자체 입력 텍스트 변경이 제대로 작동하지 않음

분류에서Dev

버튼 제목 텍스트가 지워지지 않음

분류에서Dev

보기 변경시 이미지 위에 텍스트가 표시되지 않음

분류에서Dev

목록보기가 비어있을 때 SetEmptyView가 텍스트와 버튼을 표시하지 않음

분류에서Dev

버튼 내에서 텍스트가 깨지지 않음

분류에서Dev

자바 스크립트에서 버튼 이벤트가 실행되지 않음

Related 관련 기사

  1. 1

    부트 스트랩 버튼 텍스트가 보이지 않음

  2. 2

    버튼 텍스트가 변경되지 않음

  3. 3

    텍스트 상자에 텍스트가 표시되지 않음 (라디오 버튼)

  4. 4

    Android-버튼 텍스트 중심이 작동하지 않음

  5. 5

    xml에서 Android 버튼 배경색이 변경되지 않음

  6. 6

    Onclick 버튼 초보자의 Android 앱이 실행되고 있지 않습니다.

  7. 7

    React.js 버튼 클래스가 변경되지 않음

  8. 8

    CardView 버튼과 텍스트가 정렬되지 않음

  9. 9

    버튼 텍스트가 표시되지 않음

  10. 10

    Flutter-버튼 내부의 텍스트가 변경되지 않습니다.

  11. 11

    대화 상자에서 버튼을 눌러도 텍스트가 업데이트되지 않음

  12. 12

    버튼 클릭시 텍스트 상자 값이 업데이트되지 않음

  13. 13

    버튼 텍스트 변경이 작동하지 않음 iOS

  14. 14

    버튼 클릭시 Android TextView가 업데이트되지 않음

  15. 15

    Android 목록보기 항목 클릭 텍스트 변경 버튼

  16. 16

    텍스트 상자와 버튼이 제대로 정렬되지 않음

  17. 17

    초보자 Android 프로그래머, 버튼이 작동하지 않습니까?

  18. 18

    Android : 대화 상자에서 버튼의 텍스트 변경

  19. 19

    Android : 대화 상자에서 버튼의 텍스트 변경

  20. 20

    사용자가 홈 화면으로 이동 한 후 버튼 클릭시 이미지가 변경되지 않음

  21. 21

    버튼 클릭시 반응 상태가 변경되지 않음

  22. 22

    버튼을 눌러도 상태가 변경되지 않음

  23. 23

    버튼을 눌러도 상태가 변경되지 않음

  24. 24

    선택 버튼을 통한 자체 입력 텍스트 변경이 제대로 작동하지 않음

  25. 25

    버튼 제목 텍스트가 지워지지 않음

  26. 26

    보기 변경시 이미지 위에 텍스트가 표시되지 않음

  27. 27

    목록보기가 비어있을 때 SetEmptyView가 텍스트와 버튼을 표시하지 않음

  28. 28

    버튼 내에서 텍스트가 깨지지 않음

  29. 29

    자바 스크립트에서 버튼 이벤트가 실행되지 않음

뜨겁다태그

보관