2017-01-23 40 views
0

時,我有一個應用程序從JSON獲取數據並顯示在回收視圖 ,當單擊各個回收視圖它會打開一個新的活動,以顯示全部內容。所有我想知道的是如何顯示進度對話框befrore第二項活動顯示的感謝。 這裏是我的代碼如何設置進度條回收視圖點擊

 public CustomViewHolder(View view, Context ctx, ArrayList<FeedItem> feeditem) { 
     super(view); 

     view.setOnClickListener(this); 
     this.ctx = ctx; 
     this.feeditem = feeditem; 
     this.imageView = (ImageView) view.findViewById(R.id.thumbnail); 
     this.textView2 = (TextView) view.findViewById(R.id.date); 
     this.textView3 = (TextView) view.findViewById(R.id.excerpt); 
     this.categories = (TextView) view.findViewById(R.id.categories); 
     this.textView = (TextView) view.findViewById(R.id.title); 
    } 

    @Override 
    public void onClick(View v) { 
     int position = getAdapterPosition(); 
     FeedItem feeditem = this.feeditem.get(position); 
     Intent intent = new Intent(this.ctx, ScrollingActivity.class); 
     intent.putExtra("excerpt",feeditem.getExcerpt()); 
     intent.putExtra("content",feeditem.getContent()); 
     intent.putExtra("title",feeditem.getTitle()); 
     Html.fromHtml(String.valueOf(intent.putExtra("content",feeditem.getContent()))).toString(); 
     intent.putExtra("thumbnail",feeditem.getAttachmentUrl()); 
     this.ctx.startActivity(intent); 


    } 
+1

在顯示其他活動之前是否有延遲?爲什麼你想要顯示進度對話框? –

+0

是有延遲;圖像需要時間,所以因此我希望進度對話框顯示爲圖像渲染@AbhishekJain –

回答

0

您的第二個活動來對付它。在那裏,你應該把你所有的數據加載或重處理工作在後臺線程和更新用戶界面,當你擁有的數據或處理完成。

的AsyncTask旨在服務正是爲此在UI線程

public class LoadDataTask extends AsyncTask<Void, Void, Void> { 
    public LoadDataTask(ProgressDialog progress) { 
    this.progress = progress; 
    } 

    public void onPreExecute() { 
    progress.show(); 
    } 

    public void doInBackground(Void... unused) { 
    ... load your image here ... 
    } 

    public void onPostExecute(Void unused) { 
    progress.dismiss(); 
    } 
} 

onPreExecute()onPostExecute()運行。所以你可以在這裏更新你的UI,就像展示圖片一樣。

你的第二個活動應該是現在這個樣子:

ProgressDialog progress = new ProgressDialog(this); 
progress.setMessage("Loading..."); 
new LoadDataTask(progress).execute(); 

如需進一步的幫助,檢查這些:

+0

由於加載,它的工作 –