在我的應用程序中,當我點擊按鈕時,進度條將最近啓動。我想快速開始。請任何人都可以幫助我。 onCreate()中的bshowgifts監聽器。android-進度條延遲加載,當點擊按鈕時
bShowGifts.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//vsChange
progressDlg = ProgressDialog.show(Ehome.this, "", "", true);
progressDlg.setContentView(R.layout.custom_dialog);
//Gender and age must be selected
if(ElGiftoAppData.getAppData().arSelectedGender.size() == 0)
{
progressDlg.dismiss();
String strMsg = "Please select a gender";
DisplaySelectionMessage(strMsg);
return;
}
if(ElGiftoAppData.getAppData().arSelectedAge.size() == 0)
{
progressDlg.dismiss();
String strMsg = "Please select an age";
DisplaySelectionMessage(strMsg);
return;
}
if(nMatchingGifts == 0)
{
progressDlg.dismiss();
tvCount = (TextView) findViewById(R.id.textMatchinGifts);
String strContent = "# of Matching Gifts: 0";
tvCount.setText(strContent);
String strMsg = "No gifts found! Please change the search criteria.";
DisplaySelectionMessage(strMsg);
return;
}
try
{
//Thread for getting the negative attributes values
Thread tDisplayCategories = new Thread()
{
public void run()
{
System.out.println("Showgifts : Thread:run");
handlerDisplayGifts.post(call_ShowGiftsCategoryPage);
}
};
tDisplayCategories.start();
}
catch(Exception exp)
{
progressDlg.dismiss();
}
return;
}
});
public void DisplaySelectionMessage(String strMsg)
{
//display alert dialog
AlertDialog alertDialog = new AlertDialog.Builder(Ehome.this).create();
alertDialog.setTitle("Elgifto Alert");
alertDialog.setMessage(strMsg);
alertDialog.setButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
alertDialog.show();
return;
}
更新代碼
bShowGifts.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
new showgiftsbtn().execute();
}
});
public class showgiftsbtn extends AsyncTask<Void, Void, Void>
{
private final ProgressDialog dialog = new ProgressDialog(Ehome.this);
protected void onPreExecute()
{
this.dialog.setMessage("Please Wait...");
this.dialog.show();
// put your code which preload with processDialog
if(ElGiftoAppData.getAppData().arSelectedGender.size() == 0)
{
dialog.dismiss();
String strMsg = "Please select a gender";
DisplaySelectionMessage(strMsg);
return;
}
if(ElGiftoAppData.getAppData().arSelectedAge.size() == 0)
{
dialog.dismiss();
String strMsg = "Please select an age";
DisplaySelectionMessage(strMsg);
return;
}
if(nMatchingGifts == 0)
{
dialog.dismiss();
tvCount = (TextView) findViewById(R.id.textMatchinGifts);
String strContent = "# of Matching Gifts: 0";
tvCount.setText(strContent);
String strMsg = "No gifts found! Please change the search criteria.";
DisplaySelectionMessage(strMsg);
return;
}
try
{
//Thread for getting the negative attributes values
Thread tDisplayCategories = new Thread()
{
public void run()
{
System.out.println("Showgifts : Thread:run");
handlerDisplayGifts.post(call_ShowGiftsCategoryPage);
dialog.dismiss();
}
};
tDisplayCategories.start();
}
catch(Exception exp)
{
dialog.dismiss();
}
}
@Override
protected Void doInBackground(Void... arg0)
{
// put you code here
return null;
}
protected void onPostExecute(final Void unused)
{
}
}
單擊事件表示單擊偵聽器。這是對的嗎?我把這樣的bShowGifts.setOnClickListener(新OnClickListener() \t \t { \t \t \t @覆蓋 \t \t \t公共無效的onClick(視圖v) \t \t \t {\t \t \t \t \t新showgiftsbtn()。執行(); \t} \t \t}); – naresh
這是行不通的 – naresh
public void onClick(View v) { new xyz()。execute(); –