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.
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();
}
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();
}
});
Thanks in advance for help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…