在我的应用程序中,我想显示一个活动指示器。在我的应用程序中,我有一个画廊视图,如果用户单击画廊视图中的项目,我将从 URL 加载数据并将其显示在列表视图中。在加载和显示数据之间,我需要一个指标。
我的活动代码:
gal.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
context.getInstance().setAppVariable("sectionurl", adapter.sectionurl[position]);
ListView list=(ListView)findViewById(R.id.list);
listadapter = new ListViewwithimageAdapter(this);
list.setAdapter(listadapter);
}
});
我还发现了 1 个指标代码:
ProgressDialog mDialog = new ProgressDialog(contxt);
mDialog.setMessage("Please wait...");
mDialog.setCancelable(true);
mDialog.show();
我的getview代码:
public View getView(int position, View convertView, ViewGroup parent)
{
ProgressDialog mDialog = new ProgressDialog(contxt);
mDialog.setMessage("Please wait...");
mDialog.setCancelable(false);
mDialog.show();
// TODO Auto-generated method stub
Bitmap bitmap = DownloadImage(
kickerimage[position] );
// View listView = convertView;
if (convertView == null)
{
//this should only ever run if you do not get a view back
LayoutInflater inflater = (LayoutInflater) contxt
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.homelistrow, null);
}
// else
// {
// holder.removeAllViews();
// }
// View listView;
// if (convertView == null)
// {
// listView = new View(contxt);
// LinearLayout holder = (LinearLayout)convertView.findViewById(android.R.id);
//// holder = inflater.inflate(R.layout.homelistrow, null);
// System.out.println("pos="+position);
// System.out.println("item="+getItem(position));
// else
// {
TextView textView = (TextView) convertView
.findViewById(R.id.name_label);
textView.setText(itemsarray[position]);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.icon);
imageView.setImageBitmap(bitmap);
// }
// else
// {
// listView = (View) convertView;
// }
// }
mDialog.dismiss();
return convertView ;
}
我的日志猫:
11-28 16:01:55.589: D/AndroidRuntime(788): Shutting down VM
11-28 16:01:55.589: W/dalvikvm(788): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
11-28 16:01:55.589: E/AndroidRuntime(788): Uncaught handler: thread main exiting due to uncaught exception
11-28 16:01:55.650: E/AndroidRuntime(788): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewRoot.setView(ViewRoot.java:472)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.app.Dialog.show(Dialog.java:239)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.newspaper.NewsPaperNov28MainGalleryActivity$1.onItemClick(NewsPaperNov28MainGalleryActivity.java:68)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.widget.Gallery.onSingleTapUp(Gallery.java:864)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.widget.Gallery.onTouchEvent(Gallery.java:839)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.View.dispatchTouchEvent(View.java:3709)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.os.Looper.loop(Looper.java:123)
11-28 16:01:55.650: E/AndroidRuntime(788): at android.app.ActivityThread.main(ActivityThread.java:4363)
11-28 16:01:55.650: E/AndroidRuntime(788): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 16:01:55.650: E/AndroidRuntime(788): at java.lang.reflect.Method.invoke(Method.java:521)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-28 16:01:55.650: E/AndroidRuntime(788): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-28 16:01:55.650: E/AndroidRuntime(788): at dalvik.system.NativeStart.main(Native Method)
11-28 16:01:55.739: I/dalvikvm(788): threadid=7: reacting to signal 3
11-28 16:01:55.739: I/dalvikvm(788): Wrote stack trace to '/data/anr/traces.txt'
实际上,我将此代码放在适配器类的 getview() 中。但指示器并没有结束它总是显示..请帮助我..提前谢谢..