I am developing Chat Application in Android and I want to add dynamic Chat Tabs dependent on current matched Users like attached in screenshot below :
In Screen shot Chat Tabs are at Top but I want Chat Tabs at bottom
. Now I want to develop logic in onCreate method
so that
If there are three matched users then create 3 tabs,
If there are four matched users then create 4 tabs,likewise..
I searched a lot for chat Tabs and found ways to create Chat Tabs by using TabHost
..But also found that it is deprecated,not sure.. Another way is to setup Chat Tabs in Action Bar
..Somewhere found that use ActionBarSherlock
. I am very confused about chat tabs that what to use ?
Any help will be appreciated.
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
public static TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tab_main);
// call addtab() how many times you need and pass tag and image resource id
}
private void addTab(String tag, int drawableId) {
tabHost = getTabHost();
TabHost.TabSpec spec = tabHost.newTabSpec(tag);
// tab_indicator layout contains only imageview. this is for fix image size, position
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.tab_indicator, getTabWidget(), false);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
tabHost.addTab(spec);
}
}