package kr.ac.jbnu.se.as;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView)findViewById(R.id.textview1);
String str = text.getText().toString();
if(str=="Hello world!"){
Toast.makeText(MainActivity.this, "if가 잘 작동하는군", Toast.LENGTH_SHORT).show();
}else{
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
조별 과제때문에 안드로이드를 공부하는 학생입니다.
일단은 ADT가 자동으로 생성해주는 Hello world 앱을 이용해서, 자동으로 생성된(Hello world를 출력하는) 텍스트뷰의 내용이 헬로월드인지를 체크해서 맞으면 if가 잘 작동한다는 토스트를 출력하는...
분석하기 민망한 수준의 앱인데요.
저 if문이 제대로 사용이 안된 것 같습니다... 이건 안드로이드보다는 자바 문법 자체의 문제같은데
Toast를 이용해 if문에 전달되는 boolean 값을 조사해본결과 text.getText().toString()=="Hello world!"의 값은 항상 false가 나오더군요...
정말 간단한문제인데 해결이 안되어 잠이 안오네요ㅠㅠ 도와주세요