我如何在我的应用程序中放入进度条,我搜索但我只是为了AsyncTask。在下面的代码中如何设置进度条,我没有。
@Override
public void onClick(View view) {
EditText e1 = (EditText) findViewById(R.id.input_email);
EditText p1 = (EditText) findViewById(R.id.input_password);
email = e1.getText().toString();
String password = p1.getText().toString();
String url = "url"
AQuery mAQuery = new AQuery(main.this);
mAQuery.ajax(url, String.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String data, AjaxStatus status) {
super.callback(url, data, status);
String StringData = "" + data;
if(StringData.equals("\"S\"")){
Intent intent = new Intent(main.this, MainActivity.class);
intent.putExtra("emailid",email );
startActivity(intent);
}
else{
Toast toast = Toast.makeText(main.this,"Invalid Combination of Email and Password", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
答案 0 :(得分:0)
你可以做这个班级
public class AQueryAJAXDownload extends Activity {
// AQuery object
AQuery aq;
// Progress Dialog Bar
ProgressDialog prgDialog;
// Mp3 File location
String url = "http://programmerguru.com/android-tutorial/wp-content/uploads/2014/01/jai_ho.mp3";
// Media player object
public MediaPlayer mPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Instantiate AQuery object
aq = new AQuery(this);
// Look for button click event using AQuery clicked() method
aq.id(R.id.btnProgressBar).clicked(this, "downloadSongandPlay");
}
// AQuery button click callback method
public void downloadSongandPlay(View v) {
// Mp3 file location in SD card
File file = new File(Environment.getExternalStorageDirectory().getPath()+"/pgfolder/jai_ho.mp3");
// Get SD card location
File ext = Environment.getExternalStorageDirectory();
// Target location where downloaded file to be stored
File target = new File(ext, "pgfolder/jai_ho.mp3");
// Disable button in order to avoid multiple button hits
aq.id(R.id.btnProgressBar).enabled(false);
// When Mp3 File exists under SD card
if (file.exists()) {
Toast.makeText(getApplicationContext(), "File already exist under SD card, playing Music", Toast.LENGTH_LONG).show();
// Play Music
playMusic();
// If the Music File doesn't exist in SD card (Not yet downloaded)
} else {
Toast.makeText(getApplicationContext(), "File doesn't exist under SD Card, downloading Mp3 from Internet", Toast.LENGTH_LONG).show();
prgDialog = new ProgressDialog(this); // Instantiate Progress Dialog Bar
prgDialog.setMessage("Downloading MP3 from Internet. Please wait..."); // Set Progress Dialog Bar message
prgDialog.setIndeterminate(false);
prgDialog.setMax(100); // Progress Bar max limit
prgDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // Progress Bar style
prgDialog.setCancelable(false); // Progress Bar cannot be cancelable
// Display progress dialog bar and initiate download of Mp3 file
aq.progress(prgDialog).download(url, target, new AjaxCallback<File>() {
// Once download is complete
public void callback(String url, File file, AjaxStatus status) {
// If file does exist
if (file != null) {
playMusic();
// If file doesn't exist display error message
} else {
Toast.makeText(aq.getContext(), "Error occured: Status" + status,
Toast.LENGTH_SHORT).show();
}
}
});
}
}
protected void playMusic(){
// Read Mp3 file present under SD card
Uri myUri1 = Uri.parse("file:///sdcard/pgfolder/jai_ho.mp3");
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(aq.getContext(), myUri1);
mPlayer.prepare();
// Start playing the Music file
mPlayer.start();
mPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
// Once Music is completed playing, enable the button
aq.id(R.id.btnProgressBar).enabled(true);
Toast.makeText(getApplicationContext(), "Music completed playing",Toast.LENGTH_LONG).show();
}
});
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "URI cannot be accessed, permissed needed", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "Media Player is not in correct state", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "IO Error occured", Toast.LENGTH_LONG).show();
}
}
}
有关详细信息,此链接将为您提供帮助 AQueryAJAXDownload