2016-08-29 2 views
0

내 응용 프로그램에서 진행률 표시 줄을 어떻게 넣을 수 있습니까?하지만 검색 한 있지만 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

프로세스 바는 무엇인가 도움이 될 것입니다? 'ProgressBar'라는 뜻입니까? – Egor

+0

예, 철자가 틀어서 죄송합니다. – tiya

답변

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