ProgressBar用于在界面上显示一个进度条,表示我们的程序正在加载一些数据。
package com.example.uiwidgettest2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.*; public class edittextActivity extends Activity{ private ProgressBar progressBar = null; private Button btn1 = null; private Button btn2 = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext); progressBar = (ProgressBar)findViewById(R.id.progress_bar); btn1 = (Button)findViewById(R.id.button1); btn2 = (Button)findViewById(R.id.button2); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(progressBar.getVisibility() == View.VISIBLE){ progressBar.setVisibility(View.GONE); } } }); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(progressBar.getVisibility() == View.GONE){ progressBar.setVisibility(v.VISIBLE); } } }); } }
package com.example.uiwidgettest2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.*; public class edittextActivity extends Activity{ private ProgressBar progressBar = null; private Button btn1 = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext); progressBar = (ProgressBar)findViewById(R.id.progress_bar); btn1 = (Button)findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int progress = progressBar.getProgress(); progress = progress+10; if(progressBar.getProgress() <= 100){ progressBar.setProgress(progress); } } }); } }