我只想在新活动开始前显示进度条。当我从上一个活动开始活动时,新屏幕首先显示虚拟进度条(仅有进度条的白色屏幕),并在2或3秒后开始新活动。
listCategory.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent iMenuList = new Intent(thirdstep.this, fifthscreen.class);
startActivity(iMenuList);
}
});
public class fifthscreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fifthscreen);
}
}
答案 0 :(得分:1)
您可以使用处理程序尝试如下:
listCategory.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
//Display your progressBar here
Handler mHand = new Handler();
mHand.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent iMenuList = new Intent(thirdstep.this, fifthscreen.class);
//Dismiss progressBar here
startActivity(iMenuList);
}
}, 2000);
}
}
});
您需要将此代码放在onItemClick
方法中。
答案 1 :(得分:0)
确定如果您的问题是活动需要花费大量时间才能显示,那么您可能希望在显示活动后对xml进行充气。
以下是步骤:
答案 2 :(得分:0)
您可以将宽度和高度的imageView放置为fill_parent,并经常更改其背景图像,这会产生渐进进度条的错觉。
使用另一个布局来扩展您的布局,其中imageView的宽度和高度为fill_parent,progressBar的背景图像显示初始值。然后使用处理程序..
new Handler().postDelayed(new Runnable() {
@Override
public void run()
{
imageView.setBackgroundResource(R.drawable.progressImage2);
}
}, 3200);
new Handler().postDelayed(new Runnable() {
@Override
public void run()
{
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
finish();
startActivity(intent);
}
}, 5000);
答案 3 :(得分:0)
private class log_in extends AsyncTask<String,Void,String>{
ProgressDialog pDialog;
int a=0;
boolean value1;
@Override
protected void onPreExecute(){
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Authenticating user...");
pDialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
if(a>300)
{value1=true;}
else{a++;
value1=false;}
return value1;
}
protected void onPostExecute(Boolean params){
super.onPostExecute(params);
pDialog.dismiss();
if(params){
Intent intent=new Intent(LoginActivity.this,menu.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
LoginActivity.this.startActivity(intent);
}
else{
error.setText("Wrong password or username combination");
}
}
}
只需拨打new log_in().execute();
,即可拨打下一个活动