이 코드는 내 MainActivity.java
파일에 있지만 편집 텍스트에 값을 입력하고 버튼을 누르면 관련 문자열이 인쇄되지 않습니다. 버튼을 눌렀을 때 텍스트 편집 슬롯에 입력 된 문자열을 기반으로 특정 텍스트가 표시되도록하려면 어떻게해야합니까?
public void ShowAge(View view){
EditText entered = (EditText)findViewById(R.id.typehere);
TextView value = (TextView)findViewById(R.id.answer);
if(entered.getText().toString() == "Dog"){
value.setText(R.string.dog);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
value.setTypeface(typeFace);}
else if(entered.getText().toString() == "Cat"){
value.setText(R.string.cat);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
value.setTypeface(typeFace);}
else if(entered.getText().toString() == "Meal"){
value.setText(R.string.meal);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
value.setTypeface(typeFace);}
else if(entered.getText().toString() == "Chocolate"){
value.setText(R.string.chocolate);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
value.setTypeface(typeFace);}
else if(entered.getText().toString() == "Froyo"){
value.setText(R.string.froyo);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
value.setTypeface(typeFace);}
}
String.equals () 를 사용하여 문자열을 비교 해야합니다 . 이것은 문자열의 문자를 비교합니다. 같음 연산자 ( ==
)는 다른 메모리 위치를 비교합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다