2011-06-01 90 views
0

我正在開發一個android應用程序,其中我從一個活動傳遞給另一個活動的字符串,從編輯文本框中通過單擊「確定」按鈕獲取它。字符串是一個url,它提供了一個rss feed.So加載它需要一點時間。我想顯示一個進度條來保持界面的交互性。如何在同一個按鈕上點擊一個進度條或進度對話框?如何在按鈕單擊時獲取進度條?

我的活動代碼段是

EditText Urlis=(EditText)findViewById(R.id.entry); 
    final Button button = (Button) findViewById(R.id.ok); 
    final Intent i=new Intent(this , RSSReder.class); 
final String choice=Urlis.getText().toString(); 

    i.putExtra("key", choice); 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      startActivity(i); 
     }  
    }); 
} 

}

下一個活動的代碼的某些部分是

公共類RSSReder擴展活動實現OnItemClickListener {

public String RSSFEEDOFCHOICE; 
public final String tag = "RSSReader"; 
private RSSFed feed = null; 


/** Called when the activity is first created. */ 

public void onCreate(Bundle abc) { 
    super.onCreate(abc); 
    setContentView(R.layout.next1); 


    Intent i = getIntent(); 
    RSSFEEDOFCHOICE =i.getStringExtra("key"); 

    // go get our feed! 
    feed = getFeed(RSSFEEDOFCHOICE); 

    // display UI 
    UpdateDisplay(); 

} 
+0

你是否顯示使用來自以前的活動在新類(RSSReader.class)中的url的webview ...? – 2011-06-01 07:16:14

+0

Dinesh我在列表視圖中獲取新活動中的RSS源 – 2011-06-01 07:22:08

+0

你能發佈一些新的活動的代碼,你實際上在那裏做什麼......? – 2011-06-01 07:25:31

回答

2

您可以顯示ProgressDialog i ñ如果需要一定的時間在獲得的RSS提要NewActivity:從下面的代碼 採取的幫助:

dialog = ProgressDialog.show(mParent,"","Loading,Please wait...", true); 

final Thread t=new Thread(new Runnable() { 

      public void run() { 

       //get your rss feeds here 
      } 
     }); 
     t.start(); 

     Thread t1=new Thread(new Runnable() { 

      public void run() { 
       // TODO Auto-generated method stub 
       try { 
        t.join(); 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
       new Handler().post(new Runnable() { 
        public void run() { 

         dialog.cancel(); 
              UpdateDisplay(); 

        } 
       }); 

      } 
     }); 
     t1.start(); 

希望你能理解上面的代碼在做什麼。定製它一點,並使用... :)