电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

ProgressDialog实现


发布日期:2021/11/7
 
下面我们就以ProgressDialog实现来写如下代码

[java]

package comexampleprogressbar;

import javaioIOException;

import androidosBundle;

import androidappActivity;

import androidappProgressDialog;

import androidviewMenu;

import androidviewView;

import androidwidgetButton;

public class MainActivity extends Activity {

private Button btn;

private ProgressDialog pg;

@Override

protected void onCreate(Bundle savedInstanceState)

{

superonCreate(savedInstanceState)

setContentView(Rlayoutmain)

btn=(Button)findViewById(Ridb

btnsetOnClickListener(new ButtonOnClickListener()

{

public void onClick(View view)

{

final CharSequence Body=Please wait for a moment;

final CharSequence Title=Progress Bar;

pg=ProgressDialogshow(MainActivitythis Title Body)

new Thread()

{

public void run()

{

try

{

sleep(

}

catch(Exception e)

{

eprintStackTrace()

}

finally

{

pgdismiss()

}

}

}start()

}

})

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present

getMenuInflater()inflate(numain menu)

return true;

}

}

上一篇:软件代码数字签名基本原理

下一篇:跨越边界: REST on Rails