在此代码中,我想使用环progressdialog
来打开并加载每个活动。
我的代码效果不好。在我的代码中,进度条关闭,活动在很长一段时间后打开。
我想在progressdialog
中添加onListItemClick
,请帮助我
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;
}
}
编辑,加载班级
public class LoadingScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("LoadingScreenActivity screen started");
setContentView(R.layout.loading_screen);
Spinner s = (Spinner) findViewById(R.id.mainSpinner1);
s.setVisibility(View.VISIBLE);
//do work if needed and then launch new activity
Intent mainIntent = new Intent(LoadingScreenActivity.this,Play.class);
LoadingScreenActivity.this.startActivity(mainIntent);
LoadingScreenActivity.this.finish();
}
}
答案 0 :(得分:1)
您可以使用此示例,这是LoadingActivity
,您每次需要多次显示ProgressDialog'. You can customize it by passing activity name through
Intent which is gonna be launched next. So you will be able to reuse this
Activity`时都会创建该示例。请检查一下。
在这里,您可以创建一个仅显示加载文本的屏幕和一个进度条loading_screen.xml
<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>
并且在LoadingScreenActivity.class
中,您通常会覆盖onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("LoadingScreenActivity screen started");
setContentView(R.layout.loading_screen);
Spinner s = findViewById(R.id.mainSpinner1);
s.setVisibility(View.VISIBLE);
//do work if needed and then launch new activity
Intent mainIntent = new Intent(LoadingScreenActivity.this,ProfileData.class);
LoadingScreenActivity.this.startActivity(mainIntent);
LoadingScreenActivity.this.finish();
}
这将在您的自定义任务完成后加载下一个活动。 3.从onListItemClick事件
中说出列表,打开LoadingScreenActivity创建启动加载屏幕活动的意图
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);
}
<强>更新强>
要通过点击按钮启动LoadingActivity
的情况,您只需将此代码添加到当前活动中:
yourButton.setOnCLickListener(new OnCLickListener(){
@Override
public void onCLick(View view){
Intent intent = new Intent(this, LoadingScreenActivity.class);
startActivity(intent);
}
}
在方法Play.class
onCreate()
内创建对话框
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressdialog);
dialog.show();
然后初始化加载文件,加载完成后,调用此方法dialog.dismiss();
并继续工作。