import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class ViewId extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txtArea = new TextView(this);
txtArea.setId(20);
txtArea.setText("Hello");
TextView view = new TextView(this);
view = (TextView) this.findViewById(20);
Toast.makeText(this,view.getText(), Toast.LENGTH_LONG).show();
}
}
위의 코드를 Eclipse에서 디버깅 할 때 뷰의 값이 변수 창에 null로 표시됩니다. 무엇이 문제입니까? 또는 textview의 setid 및 XML 파일을 사용하지 않고 해당 특정 ID에서 해당 텍스트보기를 retrive 다른 메서드가 있습니다.findviewbyid가 android에서 작동하지 않습니다.
http://developer.android.com/resources/tutorials/hello-world.html에 시간을 할애해야한다고 생각합니다. – ingsaurabh