In this code i want to use a ring progressdialog
for open and loading each activity.
My code not work well. In my code, progressbar closed and activity open after long time.
I want to add a progressdialog
in onListItemClick
, plz help me
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;
}
}
EDIT, loading class
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();
}
}