티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

How to disable an Android button?

어떻게 Android 버튼을 비활성화하나요?

 문제 내용 

I have created a layout that contains two buttons, Next and Previous. In between the buttons I'm generating some dynamic views. So when I first launch the application I want to disable the "Previous" button since there wont be any previous views. I also want to disable the "Next" button when there are not more views to display. Is there anyway to disable the buttons?

두 개의 버튼(Next와 Previous)을 포함하는 레이아웃을 만들었습니다. 버튼 사이에는 동적 뷰가 생성됩니다. 애플리케이션을 처음 시작할 때 이전 뷰가 없기 때문에 "Previous" 버튼을 비활성화하고, 더 이상 표시할 뷰가 없을 때 "Next" 버튼도 비활성화하려고 합니다. 버튼을 비활성화하는 방법이 있을까요?

 

screen shot of sample layout

 

 

 높은 점수를 받은 Solution 

Did you try this?

이렇게 해보셨나요?
myButton.setEnabled(false); 

 

Update: Thanks to Gwen. Almost forgot that android:clickable can be set in your XML layout to determine whether a button can be clickable or not.

업데이트: Gwen 덕분에 android:clickable을 XML 레이아웃에 설정하여 버튼을 클릭할 수 있는지 여부를 결정할 수 있습니다.

 

 

 

 가장 최근 달린 Solution 

You can disable a button from your xml but that won't be dynamic. Best way to disable button dynamically is.

XML에서 버튼을 비활성화할 수는 있지만, 이는 동적이지 않습니다. 버튼을 동적으로 비활성화하는 가장 좋은 방법은 다음과 같습니다.
myButton.setEnabled(false);

 

 

출처 : https://stackoverflow.com/questions/4384890/how-to-disable-an-android-button

반응형
댓글
공지사항
최근에 올라온 글