android处理bar问题
我的程序从服务器检索一些数据。通常需要几秒钟。我想为此生成一个处理栏。我知道如何生成它。但是关闭处理的时候怎么区分和控制呢。 我的程序:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1=(TextView)findViewById(R.id.textin);
but1=(Button)findViewById(R.id.send);
but2=(Button)findViewById(R.id.send2);
edit1=(EditText)findViewById(R.id.textout);
but1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Socket socket=null;
String mesg=edit1.getText().toString()+"\r\n";
try {
socket=new Socket("localhost",30000);
//send information to server
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println(mesg);
//receive information from server
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String mstr=br.readLine();
if(mstr!=null)
{
text1.setText(mstr);
}else
{
text1.setText("error");
}
out.close();
br.close();
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch(Exception e)
{
Log.e(DEBUG_TAG,e.toString());
}
}
});
}
这是一个客户端程序。数据量确实很大。那么我该如何做处理呢。我怎样才能控制它? 感谢!!!
My programme retrieves some data from server. Usually it takes few seconds. I want to generate a processing bar for this. And I know how to generate it. But how to distinguish and control when close processing bar.
My programme:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1=(TextView)findViewById(R.id.textin);
but1=(Button)findViewById(R.id.send);
but2=(Button)findViewById(R.id.send2);
edit1=(EditText)findViewById(R.id.textout);
but1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Socket socket=null;
String mesg=edit1.getText().toString()+"\r\n";
try {
socket=new Socket("localhost",30000);
//send information to server
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println(mesg);
//receive information from server
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String mstr=br.readLine();
if(mstr!=null)
{
text1.setText(mstr);
}else
{
text1.setText("error");
}
out.close();
br.close();
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch(Exception e)
{
Log.e(DEBUG_TAG,e.toString());
}
}
});
}
This a client program. The amount of data is really huge. So how can I do the processing bar. How can I CONTROL it?
Thank!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://sites .google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
这是一个关于进度条的精彩教程。
http://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
Here is an awsome tutorial on progress bars.
您可以为此使用进度对话框。
这是这段代码:
You can use Progress Dialog for this.
Here is this code:
如果你只是想告诉用户下载已经完成,那么你可以使用Toast。在下载开始之前抛出“正在下载”消息,并在下载完成时禁用 Toast 消息。
假设您想显示已完成下载的百分比,那么您应该实现自己的进度栏(类似于媒体播放器中的搜索栏)。继续根据完成百分比(例如每秒)更新进度条。
沙什
If you just want to tell user that downloading has been completed, then you can use Toast. Throw the message "Downloading" just before downloading starts and disable Toast message on download completion.
Suppose you want to show the % of completed download, then you should implement your own progress bar (Similar to seek bar in Media Player). Keep on updating progress bar based on % completed (say per second basis).
Shash