나는 안드로이드 개발에 초보자입니다. 나는 Java를 잘 알고 있지만 Android API는 아닙니다. 이것은 구직 신청을위한 테스트 프로그램이므로 문제를 해결하는 데 도움이 필요합니다. 버튼을 눌러 호출되는 대화 상자를 만들었지 만 대화 상자의 textview에 연결할 수 없습니다 (응용 프로그램이 충돌하면 NullPointerException이 발생 함) Eclipse IDE로도 문제가 발견되지 않습니다. 나는 지금 당신이 찾고있는 (대화 레이아웃Android : 대화 상자에 액세스 할 수 없습니다. TextView
custom_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<TextView android:id="@+id/dlgText"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:textColor="#FFF"
/>
</LinearLayout>
BalticAmadeusActivity.java
public class BalticAmadeusActivity extends Activity{
/** Called when the activity is first created. */
Button btnApie;
Button btnForma;
Dialog dlgApie;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnApie = (Button) findViewById(R.id.btnApie);
btnForma = (Button) findViewById(R.id.btnForma);
btnApie.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (v.equals(btnForma)) {
btnForma();
} else if (v.equals(btnApie)) {
btnApie();
}
return false;
}
});
dlgApie = new Dialog(this.getApplicationContext(), android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dlgApie.setContentView(R.layout.custom_dialog);
TextView dlgText = (TextView) findViewById(R.id.dlgText);
dlgText.setText("Gera uzduotis"); //at this line, app crashes
//dlgText.setText("U\u017Eduotis s\u0117kmingai \u012Fgyvendinta");
}
private void btnApie() {
// TODO Auto-generated method stub
dlgApie.show();
}
private void btnForma() {
// TODO Auto-generated method stub
}
}
main.xml의 모습은 무엇입니까? – Phil