Android 启动活动时的进度条
在这段代码中,我想使用一个环Android 启动活动时的进度条,android,progressdialog,progress,Android,Progressdialog,Progress,在这段代码中,我想使用一个环progressdialog来打开和加载每个活动 我的代码不能正常工作。在我的代码中,progressbar在长时间后关闭,活动打开 我想在onListItemClick中添加一个progressdialog,请帮助我 public class Listsoti extends ListActivity { String[] str = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14"}; @
progressdialog
来打开和加载每个活动
我的代码不能正常工作。在我的代码中,progressbar在长时间后关闭,活动打开
我想在onListItemClick
中添加一个progressdialog
,请帮助我
public class Listsoti extends ListActivity {
String[] str = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
TextView list = (TextView) findViewById(R.id.hamid);
PersianReshape.ReshapeTextview(list, "hamid1.ttf", Listsoti.this);
setListAdapter(new MyAdapter(this,
android.R.layout.simple_list_item_1,R.id.textView1, str));
}
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.listsoti, parent, false);
String[] items = getResources().getStringArray(R.array.contor);
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
TextView tv = (TextView) row.findViewById(R.id.textView1);
PersianReshape.ReshapeTextview(tv,"hamid1.ttf", Listsoti.this);
tv.setText(items[position]);
switch (position) {
case 0:
iv.setImageResource(R.drawable.dozdeh);
break;
case 1:
iv.setImageResource(R.drawable.download);
break;
default:
break;
}
return row;
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(this, str[position] +" your choose", Toast.LENGTH_LONG).show();
switch (position) {
case 0:
startActivity(new Intent(Listsoti.this, Play.class));
break;
case 1:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressdialog);
dialog.show();
startActivity(new Intent(Listsoti.this, Play.class));
break;
default:
break;
}
}
}您可以使用此示例,这是
加载活动
,每次需要显示进度对话框时都会创建此活动。您可以通过将活动名称传递给下一个要启动的
Intent来定制它。因此,您将能够多次重复使用此
活动。请检查一下
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:gravity="center" android:orientation="vertical"
android:layout_height="fill_parent" android:background="#E5E5E5">
<TextView android:text="Please wait while your data gets loaded..."
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#000000">
</TextView>
<ProgressBar android:id="@+id/mainSpinner1" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:indeterminate="true"
style="?android:attr/progressBarStyleInverse">
</ProgressBar>
</LinearLayout>
这将在自定义任务完成后加载下一个活动。
3.从onListItemClick事件中打开加载屏幕活动
创建启动加载屏幕活动的意图
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(ProfileList.this, LoadingScreenActivity.class);
startActivity(intent);
}
更新
若要通过单击按钮启动加载活动
,只需将此代码添加到当前活动中即可:
yourButton.setOnCLickListener(new OnCLickListener(){
@Override
public void onCLick(View view){
Intent intent = new Intent(this, LoadingScreenActivity.class);
startActivity(intent);
}
}
在方法onCreate()
然后初始化加载文件,加载完成后,调用此方法
dialog.disease()编码>并继续工作。储罐,但在装载筛选活动中,剖面数据无法解析为type@H.A.M.I.D,因为这是一个示例,您应该将其替换为“下一个”活动
名称。是否有可能在打开新活动时,当我触摸按钮时,会显示一个进度对话框?,不适用于列表,仅适用于按钮这是新活动中的对话框,用于执行繁重的任务。执行任务时,用户将看到进度对话框。但若你们在后台并没有繁重的任务要做,你们就不应该创建进度对话框,它运行得很快,除非你们的设备真的很慢,否则并没有人会这么做,但现在设备已经足够强大了,不能这么做。我的意思是,若你们并没有任务,你们只需要尝试设置对话框,用户甚至都看不到它,因为启动新活动的过程非常快。
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(ProfileList.this, LoadingScreenActivity.class);
startActivity(intent);
}
yourButton.setOnCLickListener(new OnCLickListener(){
@Override
public void onCLick(View view){
Intent intent = new Intent(this, LoadingScreenActivity.class);
startActivity(intent);
}
}
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressdialog);
dialog.show();