title: Android Studio - TabHost refresh tab content
body: <p>please help me..</p>
  
  <p>ok here is my problem. i use tabhost and i have 3 tabs.</p>
  
  <p>compose of SONG LIST, NEW SONGS and FAVORITES</p>
  
  <p>here is the code of the tabhost..</p>
  
  <pre><code>@Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View rootView = inflater.inflate(R.layout.fragment_fragment_one, container, false);
  
          final TabHost host = (TabHost) rootView.findViewById(R.id.tabHost);
          host.setup();
  
          dbHelper = new FragmentOne_DbAdapter(getActivity());
          dbHelper.open();
          //Clean all data
          //dbHelper.deleteAllPlayer1();
          //Add some data
          dbHelper.insertPlayer1Songlist();
          //Generate ListView from SQLite Database
  
          //Tab 1
          TabHost.TabSpec spec = host.newTabSpec("SONG LIST");
          spec.setContent(R.id.tab1);
          spec.setIndicator("SONG LIST");
          host.addTab(spec);
  
          listView = (ListView) rootView.findViewById(R.id.slPlayer1ListView);
              player1ESearch = (EditText) rootView.findViewById(R.id.player1Search);
              ImageButton dplayer1ESearch=(ImageButton) rootView.findViewById(R.id.delete);
              dplayer1ESearch.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      player1ESearch.setText("");
                  }
              });
              displayPlayer1ListView();
  
          //Tab 2
          spec = host.newTabSpec("NEW SONGS");
          spec.setContent(R.id.tab2);
          spec.setIndicator("NEW SONGS");
          host.addTab(spec);
  
              listViewNew = (ListView) rootView.findViewById(R.id.slPlayer1NewListView);
              displayPlayer1NewListView();
  
          //Tab 3
          spec = host.newTabSpec("FAVORITES");
          spec.setContent(R.id.tab3);
          spec.setIndicator("FAVORITES");
          host.addTab(spec);
  
  
  
          return rootView;
      }
  </code></pre>
  
  <p>in my tab <strong>SONG LIST</strong>, i display list from database and set it to adapter..</p>
  
  <p>in this part of the code..</p>
  
  <pre><code>private void displayPlayer1ListView() {
          Cursor cursor = dbHelper.fetchAllPlayer1();
  
          FragmentOneAdapter = new FragmentOne_Adapter(getActivity(), cursor, 0);
          listView.setAdapter(FragmentOneAdapter);
  
          player1ESearch.addTextChangedListener(new TextWatcher() {
  
              public void afterTextChanged(Editable s) {
              }
  
              public void beforeTextChanged(CharSequence s, int start,
                                            int count, int after) {
              }
  
              public void onTextChanged(CharSequence s, int start,
                                        int before, int count) {
                  FragmentOneAdapter.getFilter().filter(s.toString());
              }
          });
  
          FragmentOneAdapter.setFilterQueryProvider(new FilterQueryProvider() {
              public Cursor runQuery(CharSequence constraint) {
                  return dbHelper.fetchPlayer1ByTitle(constraint.toString());
              }
          });
      }
  </code></pre>
  
  <p>and here is my adapter bindview..</p>
  
  <pre><code>@Override
      public void bindView(View view, final Context context, final Cursor cursor) {
          // TODO Auto-generated method stub
          final ViewHolder holder = (ViewHolder) view.getTag();
  
          final int _id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
          String title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
          String artist = cursor.getString(cursor.getColumnIndexOrThrow("artist"));
          String volume = cursor.getString(cursor.getColumnIndexOrThrow("volume"));
          String type = cursor.getString(cursor.getColumnIndexOrThrow("type"));
          final String favorite = cursor.getString(cursor.getColumnIndexOrThrow("favorite"));
          String number = cursor.getString(cursor.getColumnIndexOrThrow("number"));
  
          // Populate fields with extracted properties
          holder.txtTitle.setText(title);
          holder.txtArtist.setText(artist);
          holder.txtVolume.setText(volume);
          holder.txtNumber.setText(number);
  
          if (type.matches("1")) {
              holder.buttonType.setImageResource(R.drawable.newsong);
          } else if (type.matches("2")) {
              holder.buttonType.setImageResource(R.drawable.practice);
          } else if (type.matches("0")) {
              holder.buttonType.setImageResource(R.drawable.none);
          }
  
          if (favorite.matches("0")) {
              holder.buttonHeart.setImageResource(R.drawable.heart);
          } else {
              if (favorite.matches("1")) {
                  holder.buttonHeart.setImageResource(R.drawable.heartred);
              } else {
                  holder.buttonHeart.setImageResource(R.drawable.heart);
              }
          }
  
          holder.buttonHeart.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  if (arg0 != null) {
                      FragmentOne_DbAdapter database = new FragmentOne_DbAdapter(context);
                      database.open();
                      if (favorite.matches("0")) {
                          database.updateItemFavorite(_id, "1");
                          holder.buttonHeart.setImageResource(R.drawable.heartred);
                      } else if (favorite.matches("1")) {
                          database.updateItemFavorite(_id, "0");
                          holder.buttonHeart.setImageResource(R.drawable.heart);
                      }
                  }
                  FragmentOne_Adapter.this.changeCursor(dbHelper.fetchAllPlayer1());
  
              }
          });
  
      }
  </code></pre>
  
  <p>as you can see in my adapter i have <strong>database.updateItemFavorite</strong>, in this part, this is where i update field in database if it is favorite it will set to 1 and the imageview resource will be heartred.</p>
  
  <p>now my second is <strong>NEW SONGS</strong></p>
  
  <p>in the second tab i display new songs in this part of the code..</p>
  
  <pre><code>private void displayPlayer1NewListView() {
          Cursor cursor = dbHelper.fetchAllPlayer1New();
          FragmentOneAdapterNew = new FragmentOne_AdapterNew(getActivity(), cursor, 0);
          listViewNew.setAdapter(FragmentOneAdapterNew);
      }
  </code></pre>
  
  <p>here is the bindview for my new song..</p>
  
  <pre><code>@Override
      public void bindView(View view, final Context context, final Cursor cursor) {
          // TODO Auto-generated method stub
          final ViewHolder holder = (ViewHolder) view.getTag();
  
          final int _id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
          String title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
          String artist = cursor.getString(cursor.getColumnIndexOrThrow("artist"));
          String volume = cursor.getString(cursor.getColumnIndexOrThrow("volume"));
          String type = cursor.getString(cursor.getColumnIndexOrThrow("type"));
          final String favorite = cursor.getString(cursor.getColumnIndexOrThrow("favorite"));
          String number = cursor.getString(cursor.getColumnIndexOrThrow("number"));
  
          // Populate fields with extracted properties
          holder.txtTitle.setText(title);
          holder.txtArtist.setText(artist);
          holder.txtVolume.setText(volume);
          holder.txtNumber.setText(number);
  
          if (type.matches("1")) {
              holder.buttonType.setImageResource(R.drawable.newsong);
          } else if (type.matches("2")) {
              holder.buttonType.setImageResource(R.drawable.practice);
          } else if (type.matches("0")) {
              holder.buttonType.setImageResource(R.drawable.none);
          }
  
          if (favorite.matches("0")) {
              holder.buttonHeart.setImageResource(R.drawable.heart);
          } else {
              if (favorite.matches("1")) {
                  holder.buttonHeart.setImageResource(R.drawable.heartred);
              } else {
                  holder.buttonHeart.setImageResource(R.drawable.heart);
              }
          }
  
          holder.buttonHeart.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  if (arg0 != null) {
                      FragmentOne_DbAdapter database = new FragmentOne_DbAdapter(context);
                      database.open();
                      if (favorite.matches("0")) {
                          database.updateItemFavorite(_id, "1");
                          holder.buttonHeart.setImageResource(R.drawable.heartred);
                      } else if (favorite.matches("1")) {
                          database.updateItemFavorite(_id, "0");
                          holder.buttonHeart.setImageResource(R.drawable.heart);
                      }
                  }
                  FragmentOne_AdapterNew.this.changeCursor(dbHelper.fetchAllPlayer1New());
              }
          });
  
      }
  </code></pre>
  
  <p>in my SONG LIST, after i click favorite imagebutton. it update my favorite field to 1 and set resource to heartred.</p>
  
  <p>now my problem is when i click the tab NEW SONGS. the updated favorite from SONG LIST should also appear in my NEW SONGS list.</p>
  
  <p>please help me.</p>