I have a similar problem. I have tried doing it with the 'selected' property but it doesn't seem to be working properly. If I use the 'selected' attribute of TabItemButton, the tab button is selected but it is viewed the first tab. But the fact is that it is selected the button of the tab that has to be selected every time. However, when I use the 'selected' property of TabItem, it doesn't work properly.
This is my code:
XML FILE:
<screen cleanUpWhenRemoved="true">
<_title>%TABS%</_title>
<tabfolder class="library" id="tabs">
<tabitem id="tab1">
<tabitembutton onselect="selectTab(tab1)">
<_selected>@{selectedTab1}</_selected>
</tabitembutton>
<_label>%TAB1%</_label>
#inc(/xml/tab1.xml)
</tabitem>
<tabitem id="tab2">
<tabitembutton onselect="selectTab(tab2)">
<_selected>@{selectedTab2}</_selected>
</tabitembutton>
<_label>%TAB2%</_label>
#inc(/xml/tab2.xml)
</tabitem>
</tabfolder>
</screen>
FRAME CLASS:
public class TabScreen extends MiFrame
{
private static final String SELECT_TAB = "selectTab";
.
.
.
public boolean onMessage(Object identifier, Object[] arguments)
{
boolean devolver=false;
if (SELECT_TAB.equals(identifier))
{
//arguments[0] = selected tab
TabProvider tabProvider = (TabProvider)getDataProvider();
String selectTab = (String)arguments[0];
tabProvider.setSelectTab(selectTab);
}
else
devolver=true;
return devolver;
}
.
.
.
}
DATAPROVIDER CLASS:
public class TabProvider extends DataProvider
{
/**
* Attributes that indicate which is the selected tab
*/
private boolean selectedTab1=true; //By default, when initializing the frame.
private boolean selectedTab2;
/**
* It indicates which is the currently selected tab
* It is initialized with the value TAB1, because when viewing the frame, it is shown TAB1
*/
private String selectTab=TAB1;
//Tabs that can be selected in the frame
public static final String TAB1 = "tab1";
public static final String TAB2 = "tab2";
private static final String SELECTED_TAB1 = "selectedTab1";
private static final String SELECTED_TAB2 = "selectedTab2";
.
.
.
public void setSelectedTab2(boolean selectedTab2) {
this.selectedTab2 = selectedTab2;
dispatchUpdateEvent(SELECTED_TAB2);
}
public boolean isSelectedTab2() {
return selectedTab2;
}
public boolean isSelectedTab1() {
return selectedTab1;
}
public void setSelectedTab1(boolean selectedTab1) {
this.selectedTab1 = selectedTab1;
dispatchUpdateEvent(SELECTED_TAB1);
}
protected Object getUserDefinedValue(String property)
{
Object devolver =null;
else if (SELECTED_TAB1.equals(property)) {
devolver= ""+selectedTab1;
}
else if (SELECTED_TAB2.equals(property)) {
devolver= ""+selectedTab2;
}
return devolver;
}
public String getSelectTab() {
return selectTab;
}
public void setSelectTab(String selectTab) {
this.selectTab = selectTab;
updateSelectTab(selectTab);
}
private void updateSelectTab(String selectTab)
{
if (selectTab.equals(TAB1))
{
selectedTab1=true;
selectedTab2=false;
}
else if (selectTab.equals(TAB2))
{
selectedTab2=true;
selectedTab1=false;
}
dispatchUpdateEvent(SELECTED_TAB1);
dispatchUpdateEvent(SELECTED_TAB2);
}
}
Regards,