How can i add eventListener on TabListener?
I am working in android. I am designing a TabHost
, in which I want to add onclickListener()
.
This is my code for create a TabHost
:
int number_of_tab=number_of_records/4;
for(int i=0;i<number_of_tab;i++)
{
intent = new Intent().setClass(this,Latest_MyActivity.class);
intent.putExtra("EX_START_POINT", i);
Log.v(TAG,"---album activity is called---" + "---the value of i---" + i);
spec = tabHost.newTabSpec(i+"").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
tabHost.addTab(spec);
Log.v(TAG,"---tabHost.getCurrentTabTag()--->>"+tabHost.getCurrentTabTag());
}
I want to know eventListener, so please suggest the code for that.
This is another function which is exist in second class:
void makeListOfSongs()
{
Bundle extras=getIntent().getExtras();
display_tag=extras.getInt("EX_START_POINT");
for (int i = display_tag*10; i < display_tag+5; i++) {
musicid[i] = new TextView(this);
musicid[i].setText("Music Id = "+sitesList.getMusicId().get(i));
title[i] = new TextView(开发者_C百科this);
title[i].setText("Title = "+sitesList.getTitle().get(i));
title_of_song[i]=sitesList.getTitle().get(i);
layout.addView(musicid[i]);
layout.addView(title[i]);
}
So if i select the first tab then list of song from 10 to 15 should display in list, if i select tab 2 then song from 20 to 25 should show in the list. So please suggest me what should i do to make such type of event Listener on the tabhost.
Thank you in advance...
You can add a onTabChangedListener to the tab host like
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override public void onTabChanged(String tabId) { } });
This is the solution for my above question :- i have solved this problem by taking help of google:-
- implement OnTabChangeListener interface on your activity.
override the method onTabChanged()
public void onTabChanged(String tabId) { //do here whatever you want }
精彩评论