私のアプリケーションでは、アクティビティインジケーターを表示したいと思います。私のアプリケーションでは、ギャラリービューがあります。ユーザーがギャラリービューのアイテムをクリックすると、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 ;
}
私のLogcat:
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()に配置しましたが、インジケータが常に表示されているわけではありません。助けてください。よろしくお願いします。