我浪費了很多時間試圖寫:走動作爲單獨的類
private void showAbout() {
Dialog dialog = new Dialog(Generator.this);
dialog.setContentView(R.layout.about);
dialog.setTitle(getString(R.string.about));
dialog.setCancelable(true);
try {
TextView tv_version = (TextView) dialog.findViewById(R.id.tv_version);
tv_version.setText("Version number: " + getPackageManager().getPackageInfo(
getPackageName(), 0).versionName);
TextView tv_createdBy = (TextView) dialog
.findViewById(R.id.tv_createdBy);
tv_createdBy.setText(getString(R.string.made_by));
} catch (NameNotFoundException e) {
Log.e(TAG, "showAbout()", e);
} finally {
dialog.show();
}
}
在在希望的一類,使我的代碼更易讀。
我寫這樣的:
private void showAbout() {
About about = new About();
about.show();
}
public class About extends Activity {
String TAG = "About";
Dialog dialog;
/**
*
*/
public About() {
dialog = new Dialog(About.this);
}
public void show() {
dialog.setContentView(R.layout.about);
dialog.setTitle(getString(R.string.about));
dialog.setCancelable(true);
try {
TextView tv_version = (TextView) dialog
.findViewById(R.id.tv_version);
tv_version
.setText("Version number: "
+ getPackageManager().getPackageInfo(
getPackageName(), 0).versionName);
TextView tv_createdBy = (TextView) dialog
.findViewById(R.id.tv_createdBy);
tv_createdBy.setText(getString(R.string.made_by));
} catch (NameNotFoundException e) {
Log.e(TAG, "showAbout()", e);
} finally {
dialog.show();
}
}
}
的Bt這是行不通的。它似乎是在創建對話框時崩潰的,但我不知道如何以另一種方式編寫它。
任何想法?
你怎麼稱呼這項活動?你有沒有在androidmanifest.xml中定義活動? – ariefbayu 2012-01-31 13:52:52
這是一個很好的觀點。您如何確定如何定義活動?我並不擅長這一點 - 但是。 – ringkjob 2012-01-31 18:15:26
你想如何顯示'about'?在彈出對話框?或在另一個活動? – ariefbayu 2012-02-01 01:17:08