Диалог сбой приложения - PullRequest
0 голосов
/ 31 октября 2011

Хорошо, просто чтобы знать, я скопировал код с сайта Android, так что я не думаю, что что-то не так.

Проблема в том, что при нажатии кнопки происходит сбой. И вылетает из кода диалога, потому что у меня там больше ничего нет.

Код:

MainDialog.xml:

          <?xml version="1.0" encoding="utf-8"?>
          <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"
          >
          <ImageView 
           android:id="@+id/image"
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
           android:layout_marginRight="10dp"
           />
          <TextView android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:textColor="#FFF"
          />

          </LinearLayout>

А на случай, если кнопка 1 нажата:

                    Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);

        dialog.setContentView(R.layout.maindialog);
        dialog.setTitle("Custom Dialog");

        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Hello, this is a custom dialog!");
        ImageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource(R.drawable.icon);    
        dialog.show();  

1 Ответ

1 голос
/ 31 октября 2011

Вы используете контекст Activity и добавляете вызов к dialog.show();:

    Context mContext = this; //Assumes you are calling this from within an activity
    Dialog dialog = new Dialog(mContext);

    dialog.setContentView(R.layout.maindialog);
    dialog.setTitle("Custom Dialog");

    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);    
    dialog.show();  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...