久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在按鈕單擊時刷新片段選項卡內容

How to refresh fragment tab content on button click(如何在按鈕單擊時刷新片段選項卡內容)
本文介紹了如何在按鈕單擊時刷新片段選項卡內容的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我是 Android 的新手,我正在實施一個小項目,其中我有來自一個 Drupal 網站的新聞.這個應用程序有 3 個標簽,每個標簽都有一個包含特定內容的文章列表.文章列表由以線性布局排列的 textviews 和 imageviews 創建.當我點擊標題時,文章正在以詳細信息打開.這些文章是通過 HTTP POST 和 ViewJSON 模塊從 Drupal 站點加載的.選項卡是使用 FragmentActivity 和 TabHost 創建的.一切都很好,直到這里都可以正常工作.

I'm really new in Android and I'm implementing a small project in which I have news from one Drupal website. This app is with 3 tabs and every tab have a list of articles with specific content. The list of articles is created by textviews and imageviews arranged in linearlayout. When I click on the title, the article is opening with details. Those articles are loaded from Drupal site throught HTTP POST and ViewJSON module. Tabs are created with FragmentActivity and TabHost. Everything's ok and works fine until here.

我的問題是我想制作一個刷新按鈕,放置在標簽上,當我按下它時,文章列表必須刷新或重新加載并保持當前標簽打開.我試圖替換標簽片段內容并重新打開它,但是當我點擊一篇文章的標題打開它時,標簽內容保留在所有片段下的堆棧中.我提到當我點擊文章標題時,會打開一個新片段.我發送了文章的 ID 作為參數,并在同一個片段中打開了文章的內容.

My problem is that I want to make one refresh button, to be placed over tabs and when I press it, the list of articles must refresh or reload and keep the current tab opened. I tried to replace tab fragment content and re-open it, but when I click on the title of one article to open it, the tab content remain in stack under all fragments. I mention that when I click on article's title, one new fragment is opening. I sent an id of the articles as an argument and in the same fragment I open the article's content.

我正在嘗試使用此代碼,但沒有成功.

I was trying with this code but no succes.

Button btn_refresh = (Button) findViewById(R.id.btn_refresh);
        btn_refresh.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                 String current_tab = mTabHost.getCurrentTabTag(); 
                 if(current_tab.contains("POPULARE")){

                     Fragment f;
                     f = new PopulareActivity(); 
                     FragmentTransaction ft =   getSupportFragmentManager().beginTransaction(); 
                     ft.replace(R.id.tot,f);   
                     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
                     ft.commit();
               }
                 if(current_tab.contains("RECOMANDATE")){

                     Fragment f;
                     f = new RecomandateActivity(); 
                     FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
                     ft.replace(R.id.tot,f);   
                     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
                     ft.commit(); 
                 } 

更確切地說,我在應用程序上輸入,按 Tab2(顯示來自 tab2 的文章列表),按刷新按鈕,打開一篇文章,按移動設備的后退按鈕并顯示 tab2 的內容.現在,我在 tab1 上輸入(并顯示來自 tab1 的文章列表),從 tab1 列表中打開一篇文章,顯示我需要的內容,然后在移動設備上按下后退按鈕.此時顯示的是 tab2 的內容(我按下刷新按鈕的 tab2 中的文章列表.).

More exactly I enter on app, press Tab2 (show the list of articles from tab2), press refresh button, open one article, press the back button of mobile device and show me the content of tab2. Now, I enter on tab1 (and show the list of articles from tab1), open one article from the list of tab1, show me what I need, and press the back button from mobile. In this moment is shown the tab2 content (the list of articles form tab2 from where I pressed the refresh button.).

要打開我使用的文章的詳細信息:

To open details of an article I use:

           tv.setOnClickListener(new View.OnClickListener() { 
                    public void onClick(View v) { 

                             Fragment f;
                             f = new DetaliiActivity();
                             Bundle data = new Bundle();  
                             data.putInt("id", nid);
                             f.setArguments(data);
                             FragmentTransaction ft = getFragmentManager().beginTransaction();

                             ft.replace(R.id.tot,f);

                             ft.addToBackStack(null); 
                             ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
                             ft.commit(); 
                    }
                });

提前感謝您的幫助!

推薦答案

要刷新片段的內容,可以保留對片段的引用,并調用公共(例如)refresh() 方法.示例:

To refresh the contents of a fragment, you could keep a reference to the fragment, and call a public (for example) refresh() method in that fragment. Example:

public class ArticleTabFragmentActivity extends FragmentActivity{
  private PopulareFragment populareFragment;
  private RecomandateFragment recomandateFragment;

  <code>

  private void bindView(){
    Button btn_refresh = (Button) findViewById(R.id.btn_refresh);

    btn_refresh.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                 String current_tab = mTabHost.getCurrentTabTag(); 
                 if(current_tab.contains("POPULARE")){
                   populareFragment.refresh();
                 } else if(current_tab.contains("RECOMANDATE")){
                   recomandateFragment.refresh();
                 } 
    });
  }



}

public class PopulareFragment extends Fragment{  

  public void refresh(){
    <refresh the contents of the fragment>
  }

}

<Same for other fragment>

現在,當您創建標簽片段時,就像 PupulareFragment 一樣,使用 pupulareFragment 實例變量來存儲片段.所以在刷新按鈕的onClick方法中是可用的.

Now when you create the tab fragment, like the PupulareFragment, use the pupulareFragment instance variable to store the fragment. So it is available in the refresh button onClick method.

這樣刷新時不會替換/創建任何新片段.因此,在轉到文章詳細信息活動后返回 tabActivity 可能也可以正常工作.

This way you are not replacing/creating any new fragments when refreshing. So going back to tabActivity after going to de article details activity, would probably work fine aswell.

這篇關于如何在按鈕單擊時刷新片段選項卡內容的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Developing PHP with Eclipse on a remote server (FTP) on Windows(在 Windows 上的遠程服務器 (FTP) 上使用 Eclipse 開發 PHP)
How to synchronize files over FTP with Eclipse RSE?(如何通過 FTP 與 Eclipse RSE 同步文件?)
FTPClient corrupts the images while uploading to ftp server on android?(FTPClient 在上傳到 android 上的 ftp 服務器時損壞圖像?)
FTP zip upload is corrupted sometimes(FTP zip 上傳有時會損壞)
Android FTP Library(Android FTP 庫)
Format Float to n decimal places(將浮點數格式化為 n 位小數)
主站蜘蛛池模板: 日韩欧美亚洲 | 黄a网| 中文字幕亚洲视频 | 欧美成人a∨高清免费观看 91伊人 | 日韩激情一区 | 精品二区| 亚洲九色 | 国产伦精品一区二区三区四区视频 | 操操日 | 国产成人精品免高潮在线观看 | 蜜臀久久99精品久久久久野外 | 国产精品久久久久久久一区探花 | 日本黄视频在线观看 | 欧美精品在线免费 | 久久亚洲一区二区三区四区 | 成人免费淫片aa视频免费 | 在线免费中文字幕 | 不卡一区二区三区四区 | 日韩精品1区2区3区 成人黄页在线观看 | 欧美激情在线精品一区二区三区 | 性色在线| 久久久精品一区 | 成人av播放 | 亚洲视频精品 | 四虎在线观看 | 综合精品久久久 | 成人国产在线视频 | 日韩成人免费av | 久久久久久国 | 久久久久国产成人精品亚洲午夜 | 97精品一区二区 | 久久精品亚洲国产 | 免费人成激情视频在线观看冫 | 精品久久久久久久久久久久久久 | 日韩亚洲一区二区 | 97视频在线观看免费 | 在线一区视频 | 欧美片网站免费 | 激情六月丁香婷婷 | 操久久 | 久久天天躁狠狠躁夜夜躁2014 |