gpt4 book ai didi

java - Android 进度对话框未关闭

转载 作者:行者123 更新时间:2023-12-01 08:07:51 25 4
gpt4 key购买 nike

我想在页面布局中显示进度对话框。我在下面的代码中实现了。进度对话框未关闭并且继续运行。当我单击上一页中的图像时,它将导航到下一个布局,我希望此布局在从服务器下载所有数据并将其显示在列表中之前显示进度对话框当前的布局。显示进度对话框并在后台显示列表,但进度对话框继续运行并且不会关闭。我不知道我哪里错了。请帮忙。

ProgressDialog pg;
String[] ar;
public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.filename);
pg=ProgressDialog.show(this, "ABC", "Downloading .....",true);

Thread dt= new Thread(new Runnable()
{
public void run()
{
try
{
String addr=Util.url;
URL url = new URL(urlname);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(5000);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String x = "";
String total = "";
int i=0;
ArrayList<String> content = new ArrayList();
while((x = r.readLine()) != null)
{
content.add(x);
}
in.close();
r.close();
ar= content.toArray(new String[content.size()]);

}
catch(Exception e1){
handler.sendEmptyMessage(0);
}

}

});

dt.start();
try{
dt.join();

}catch(Exception e){
handler.sendEmptyMessage(0);
}

try{
if(ar[0].toString().trim()!="")
{
android.view.Display display1 = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
TableLayout tbl1 = (TableLayout)findViewById(R.id.tableLayout2);

TableRow newRow1 = (TableRow) new TableRow(this);
TextView txt=(TextView) new TextView(this);
txt.setText("No");
txt.setGravity(Gravity.LEFT);
txt.setTextColor(Color.RED);
txt.setTextSize(18);

TextView txt1=(TextView) new TextView(this);
txt1.setText("NAME");
txt1.setTextColor(Color.RED);
txt1.setTextSize(18);
txt1.setGravity(3);

TextView txt2=(TextView) new TextView(this);
txt2.setText("DATE");

txt2.setTextColor(Color.RED);
txt2.setTextSize(18);
txt.setGravity(3);

TextView txt3=(TextView) new TextView(this);
txt3.setText("VALUE");
txt3.setTextColor(Color.RED);
txt3.setTextSize(18);
txt3.setGravity(Gravity.RIGHT);


txt.setWidth((int)(display1.getWidth()/4));
txt1.setWidth((int)(display1.getWidth()/4));
txt3.setWidth((int)(display1.getWidth()/4));
txt2.setWidth((int)(display1.getWidth()/4));


newRow1.addView(txt2);
newRow1.addView(txt);
newRow1.addView(txt1);
newRow1.addView(txt3);
tbl1.addView(newRow1);

for(int t=0;t<(ar.length);t++)
{
android.view.Display display = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
TableLayout tbl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow newRow = (TableRow) new TableRow(this);
newRow.setClickable(true);
TextView tx=(TextView) new TextView(this);
String temp=ar[t].toString();
tx.setText(temp);
tx.setTextColor(Color.WHITE);
tx.setGravity(Gravity.LEFT);
tx.setTextSize(15);

t=t+1;

TextView tx1=new TextView(this);
tx1.setText(ar[t].toString());
tx1.setGravity(Gravity.LEFT);
tx1.setTextColor(Color.WHITE);
tx1.setTextSize(15);


t=t+1;

TextView tx2=new TextView(this);
tx2.setText(ar[t].toString());
tx2.setGravity(Gravity.LEFT);
tx2.setTextColor(Color.WHITE);
tx2.setTextSize(15);

t=t+1;

TextView tx3=new TextView(this);
tx3.setText(ar[t].toString());
tx3.setGravity(Gravity.RIGHT);
tx3.setTextColor(Color.WHITE);
tx3.setTextSize(15);

tx3.setWidth((int)(display.getWidth()/4));
tx.setWidth((int)(display.getWidth()/4));
tx1.setWidth((int)(display.getWidth()/4));
tx2.setWidth((int)(display.getWidth()/4));

newRow.addView(tx);
newRow.addView(tx2);
newRow.addView(tx1);
newRow.addView(tx3);

newRow.setId(t);

tbl.addView(newRow);
}

}
}
catch(Exception e){
pg.dismiss();
handler.sendEmptyMessage(0);
}

}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {

Toast.makeText(this,"Network not available!.... ", Toast.LENGTH_LONG).show();
}
};

最佳答案

将此行添加到您想要关闭对话框的位置。

if(pg.isShowing())pg.dismiss();

关于java - Android 进度对话框未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20043789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com