Extend DialogActivity API demo to show off new window re-measuring.

Change-Id: Ia04dbf95131d5cffbdd3ae0c22758da7f6d28a1b
This commit is contained in:
Dianne Hackborn
2010-12-02 21:51:11 -08:00
parent 6893c37267
commit ae1d79d3f4
5 changed files with 67 additions and 11 deletions

View File

@@ -19,10 +19,17 @@ package com.example.android.apis.app;
// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.example.android.apis.R;
import com.example.android.apis.app.ForegroundService.Controller;
/**
* <h3>Dialog Activity</h3>
@@ -50,5 +57,30 @@ public class DialogActivity extends Activity {
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
Button button = (Button)findViewById(R.id.add);
button.setOnClickListener(mAddContentListener);
button = (Button)findViewById(R.id.remove);
button.setOnClickListener(mRemoveContentListener);
}
private OnClickListener mAddContentListener = new OnClickListener() {
public void onClick(View v) {
LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
ImageView iv = new ImageView(DialogActivity.this);
iv.setImageDrawable(getResources().getDrawable(R.drawable.icon48x48_1));
iv.setPadding(4, 4, 4, 4);
layout.addView(iv);
}
};
private OnClickListener mRemoveContentListener = new OnClickListener() {
public void onClick(View v) {
LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
int num = layout.getChildCount();
if (num > 0) {
layout.removeViewAt(num-1);
}
}
};
}