开发者

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"
       开发者_如何学Python    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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜