안드로이드 개발 질문/답변
(글 수 45,052)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id ="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello"
/>
</LinearLayout>
이렇게 xml 파일이 있을때 TextView 에 있는 android:text="Hello" 이 부분을 main.java 에서 읽어 올수 있는 방법이 없나요??
그냥 간단하게 생각한 부분은 R.id.text 로 접근을 하면 되겠구나 했는데... 안되더라구요...
혹시 아시는분 계신가요...???




왜 안되죠?
TextView tv = (TextView)findViewById(R.id.text);
String text = tv.getText().toString()하면 될텐데요.
setContentView에서 레이아웃을 잘못 불러오신건 아닐지요