Czechnology
Czechnology

Reputation: 14992

Drawing in Dialog

I'd like to display a custom Dialog and then display some results for the user - that's not a problem. But I'd also like to draw a visual representation of the data over the text.

    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.progress_overview);
    dialog.setTitle(getString(R.string.progress_overview));

    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("results...");

progress_overview.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="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="10dp"
          >
<com.name1.name2.ProgressDrawableView android:id="@+id/progress_image"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:layout_margin="10dp"
           />
<TextView android:id="@+id/text"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:textColor="#FFF"
          />
</LinearLayout>

The problem is, if I do it like this, I am unable to access the methods of my ProgressDrawableView View that is displayed (using findViewById returns null pointer).

Could you please suggest a solution or a different way if my approach is all wrong, please? (I'm new to android dev) Thanks

Upvotes: 1

Views: 1072

Answers (1)

Zelimir
Zelimir

Reputation: 11028

You need to use LayoutInflater to inflate the View attached to your layout.Then it is easy. It would be something like this:

LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.progress_overview, null);

myProgressImage = (ProgressDrawableView) layout.findViewById(R.id.progress_image);
mProgressText = (TextView) layout.findViewById(R.id.text);

dialog.setContentView(layout);

Upvotes: 2

Related Questions