2012-11-28 72 views
0

在我的應用程序中,我想顯示活動指示器。在我的應用程序中,我有一個galleryview,如果用戶點擊galleryview中的項目,我將從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()class.But指示燈未結束其總是showing..Please幫我..Thanks提前..

回答

3

你需要調用

加載完成後,您可以使用

編輯:

我正在添加我用於類似任務的代碼。

//This is my AsyncTask which needed some time 
new InsertDbTask().execute(); 


//Actual task 
public class InsertDbTask extends AsyncTask<Void, Void, Void> { 
     private final ProgressDialog dialog = new ProgressDialog(mContext); 

     @Override 
     protected Void doInBackground(Void... params) { 
      // TODO Auto-generated method stub 
      try { 
       prepareInsert(); 
      } catch (Exception e) { 
       // Log.e("Error: ", e.getMessage()); 
      } 
      return null; 
     } 

     @Override 
     protected void onPreExecute() { 
      // TODO Auto-generated method stub 
      super.onPreExecute(); 
      this.dialog.setCanceledOnTouchOutside(false); 
      this.dialog.setMessage("Inserting Record In Local DB Please Wait."); 
      this.dialog.show(); 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      // TODO Auto-generated method stub 
      super.onPostExecute(result); 

      if (this.dialog.isShowing()) { 
       this.dialog.dismiss(); 
      } 
      saveButton.setEnabled(true); // enable save button after execution of prepareInsert(). 

     } 

    } 

public void prepareInsert() 
{ 
     // Do something 
} 
+0

感謝user1858914 ji ..但我沒有得到輸出.. – Subburaj

+0

是什麼問題?對話框正在顯示? – 2012-11-28 10:30:11

+0

請參閱我的logcat用戶1858914。 – Subburaj

0

您需要的時候列表加載駁回該項進度對話框放置進度對話框代碼gal.setOnItemClickListener &。

+0

感謝rohit lagu ..我試過了。但它顯示錯誤lik ..看我的logcat .. – Subburaj

+0

什麼其他事情rohit lagu? – Subburaj

+0

不添加getview()類。 getview每次調用以創建佈局行。所以你需要在獲取數據之前加入asynctask代碼。 –