作者laugher (.。oO)
看板AndroidDev
标题Re: [问题] 请问如何在另一个class中使用alertdialog
时间Fri May 31 13:47:49 2013
※ 引述《laugher (.。oO)》之铭言:
: public void showItemCategory(Context ct) {
: String[] stra_item_category =
: getResources().getStringArray(R.array.stra_item_category);
: AlertDialog.Builder dlg_item_category = new AlertDialog.Builder(ct);
: dlg_item_category.setTitle(getString(R.string.str_dlg_item_category_title));
: dlg_item_category.setNeutralButton(getString(R.string.str_cancel), null);
: dlg_item_category.setItems(stra_item_category,
: new DialogInterface.OnClickListener() {
: public void onClick(DialogInterface dialog, int index) {
: showItemList(index);
: }
: }
: );
: dlg_item_category.show();
: }
我找到问题了
上面的函式里的getResources或是getString等会读取xml资源的都要改成
ct.getResources或ct.getString
因为目前的activity仍是RoamingMap
感谢版友的帮忙
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.72.155
1F:→ henry4343:我比较好奇你的c2是class要怎麽找到getString... 05/31 14:15
2F:→ henry4343:应该会直接报错误吧 05/31 14:15
3F:→ henry4343:还是你的c2有继承什麽东西? 05/31 14:16
4F:→ laugher:c2我继承Activity 05/31 14:23
5F:→ henry4343:你的写法一整个怪,Activity用intent不是用new吧 05/31 14:59
6F:→ henry4343:你要在RoamingMap显示alert应该code写在RoamingMap吧 05/31 15:00
7F:→ henry4343:我一开始还以为你写在一个class方便其他activity使用 05/31 15:00
8F:→ laugher:我分成另一个class是因为我想把他弄成函式库的样子 05/31 15:31
9F:→ laugher:比如管理"item"的所有功能都放在同一个class里 05/31 15:31
10F:→ henry4343:那你就不该extends任何东西 单纯都做class使用就好 05/31 15:41
11F:→ laugher:但那些功能仍是会需要像AlertDialog的能力啊 05/31 15:43
12F:→ henry4343:这...你的程式观念似乎问题满大的 05/31 16:11
13F:→ laugher:若你方便的话,可否请教你上述那些的论点跟原因何在? 05/31 19:04
14F:→ KeySabre:要用dialog的activity传context参数进去、传dialog回来就 06/02 19:16
15F:→ KeySabre:好,工具类别继承activity意义上不对。 06/02 19:16