Android 不旋转的对话框
下面是代码,如果用户单击按钮,当前将显示progressdialog,并且“环”没有旋转。但是如果我将progreedialog的代码粘贴到onCreate下,“环”将在屏幕加载后旋转。帮我找出哪里出了问题 员工选择课程:Android 不旋转的对话框,android,progressdialog,Android,Progressdialog,下面是代码,如果用户单击按钮,当前将显示progressdialog,并且“环”没有旋转。但是如果我将progreedialog的代码粘贴到onCreate下,“环”将在屏幕加载后旋转。帮我找出哪里出了问题 员工选择课程: public class StaffChoice extends Activity { @Override protected void onCreate(Bundle savedInstanceState) {
public class StaffChoice extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.staffchoices);
}
public void onClickCategory(final View view)
{
final ProgressDialog progress=ProgressDialog.show(this, "Please wait", "Loading ...", true);
new Thread()
{
public void run()
{
Intent intent = new Intent(view.getContext(), Category.class);
startActivity(intent);
progress.dismiss();
}
}.start();
}
}
在类别类中创建时:
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
final ListView lvCategory = (ListView) findViewById(R.id.lvCategory);
SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try
{
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
final String[] strCategory = new String[resultString.getPropertyCount()];
for(int i =0; i<resultString.getPropertyCount(); i++)
{
SoapObject array = (SoapObject) resultString .getProperty(i);
strCategory[i] = array.getProperty(0).toString(); //get category
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strCategory);
lvCategory.setAdapter(adapter);
lvCategory.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, final View arg1, int arg2, long arg3) {
Intent intent = new Intent(arg1.getContext(), CategoryGames.class);
startActivity(intent);
}
});
}
catch(Exception e)
{
String[] items = { "No Internet Connection, Please try again" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
lvCategory.setAdapter(adapter);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
最终ListView lvCategory=(ListView)findViewById(R.id.lvCategory);
SoapObject请求=新的SoapObject(名称空间、方法名称);
SoapSerializationEnvelope soapEnvelope=新的SoapSerializationEnvelope(soapEnvelope.VER11);
soapEnvelope.dotNet=true;
setOutputSoapObject(请求);
AndroidHttpTransport aht=新的AndroidHttpTransport(URL);
尝试
{
aht.call(SOAP\u动作,soapEnvelope);
SoapObject resultString=(SoapObject)soapEnvelope.getResponse();
最终字符串[]strCategory=新字符串[resultString.getPropertyCount()];
对于(int i=0;i您必须在线程运行时将任务或时间放入线程中,此时会显示进度对话框,但当任务/时间完成时,进度对话框将关闭
与其用线,不如用线
new Thread()
{
public void run()
{
try{
Thread.sleep(10*1000); //10 seconds
}catch(Exception e){
}
handler.sendEmptyMessage(0);
}
}.start();
我使用AsyncTask来代替线程
protected void onCreate(Bundle savedInstanceState)
{
new loadPage().execute(null, null, null);
}
public class loadPage extends AsyncTask<String, Integer, Void> {
private ProgressDialog pdia;
@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(AppDetails.this);
pdia.setMessage("Loading...");
pdia.show();
}
@Override
protected Void doInBackground(String... arg0) {
// TODO Auto-generated method stub
}
@Override
protected void onPostExecute(Void unused) {
pdia.dismiss();
}
}
创建时受保护的void(Bundle savedInstanceState)
{
new loadPage().execute(null,null,null);
}
公共类loadPage扩展了异步任务{
私家侦探;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pdia=新建进度对话框(AppDetails.this);
pdia.setMessage(“加载…”);
pdia.show();
}
@凌驾
受保护的Void doInBackground(字符串…arg0){
//TODO自动生成的方法存根
}
@凌驾
受保护的void onPostExecute(未使用的void){
pdia.discouse();
}
}
从哪里调用了onClickcategory()方法?从xml…android:onClick=“onClickcategory”你在run()中没有任何任务,线程开始并转到处理程序…所以用户需要等待10秒“假旋转”才能进入下一个屏幕?我不认为这是一个好的解决方案。不过,谢谢:)这只是一个例子,你想等待多少时间进入下一个屏幕。如果你不等待,那么就不需要放线程。实际上,它是从互联网上获取数据的,所以“等待时间”非常取决于互联网连接本身:)所以放在运行方法中,我写在回答任务中。看到这个tuts hey@melvincs,我和你有同样的问题,那么你想好了吗?我也需要解决方案,如果你有任何想法,请回复我,谢谢