ActionBar Tab Listener - xamarin.android

I have a simple layout with an ActionBar and I would like to show a message when a user selects a tab. I've implemented ActionBar.ITabListener and OnTabSelected but it doesn't work. What is wrong with the code?
Here's the code:
namespace ICSTabs
{
[Activity (Label = "ICSTabs", MainLauncher = true)]
public class Activity1 : Activity, ActionBar.ITabListener
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
ActionBar bar = ActionBar;
bar.NavigationMode = ActionBarNavigationMode.Tabs;
bar.AddTab (bar.NewTab ().SetText ("TEXT1")
.SetTabListener (this));
bar.AddTab (bar.NewTab ().SetText ("TEXT2")
.SetTabListener (this));
bar.AddTab (bar.NewTab ().SetText ("TEXT3")
.SetTabListener (this));
}
public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft)
{
Toast.MakeText(this, "Some text", ToastLength.Short);
}
public void OnTabUnselected (ActionBar.Tab tab, FragmentTransaction ft)
{
}
public void OnTabReselected (ActionBar.Tab tab, FragmentTransaction ft)
{
}
}
}

After constructing a Toast object, you need to call the show() method to actually display the Toast. Here is the code.
public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft)
{
Toast.MakeText(this, "Some text", ToastLength.Short).Show();
}

Related

Disable ValueChangeListener

I'm new of vaadin and now I'm running in the following trouble. I have a TabSheet that contains a few tabs.
Now my Tax Code component setted in immediate mode and others it has a the following ValueChangeLister
TextField taxCode = new TextField();
taxCode.setImmediate(true);
taxCode.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
if(taxCode.isModified()){
searchByTaxCode(taxCode.getValue());
}
}
});
then each time that the user changes the value to taxCode component, the method searchByTaxCode is invoked. This happens also when the user switch from Tab2 to Tab1 and I don't want this?
How can I fix this problem?
This simple test app does not fire the ValueChangeEvent when switching tabs, only when actually changing the value in the TextField. You have something more that could influence the behaviour?
public class TabSheetEventsUI extends UI {
#WebServlet(value = "/tabsheetevents/*", asyncSupported = true)
#VaadinServletConfiguration(productionMode = false, ui = TabSheetEventsUI.class)
public static class Servlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest request) {
TabSheet tabSheet = new TabSheet();
Panel tab1 = new Panel("Tab 1");
Panel tab2 = new Panel("Tab 2");
tabSheet.addTab(tab1);
tabSheet.addTab(tab2);
final TextField tab1tf = new TextField("tab1tf");
tab1tf.setImmediate(true);
tab1tf.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
System.out.println("Value change event catched.");
}
});
tab1.setContent(tab1tf);
setContent(tabSheet);
}
}

SMARTGWT, menu item width not changing

I am using a MenuItem in my application but its showing all over the page , please have a look at the attachment , i am trying for hours and searched for but this width is not reducing ,
I am using the demo application of SmartGWT , using its code but i cant figure out whats the issue
any idea
thanks
code snippet:
itemListMenu = new Menu();
itemListMenu.setCellHeight(22);
MenuItem detailsMenuItem = new MenuItem("Show Details");
detailsMenuItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
searchItemDetails.selectTab(0);
searchItemDetails.updateDetails();
}
});
MenuItem editMenuItem = new MenuItem("Edit Item");
editMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
searchItemDetails.selectTab(1);
searchItemDetails.updateDetails();
}
});
MenuItem deleteMenuItem = new MenuItem("Delete Item");
deleteMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
userGrid.removeSelectedData();
searchItemDetails.clearDetails(null);
}
});
itemListMenu.setData(detailsMenuItem, editMenuItem, deleteMenuItem);
Can we have a look at the code of the menu itself, did you set its width?
I tried your code
static void testMenu(){
Menu itemListMenu = new Menu();
itemListMenu.setCellHeight(22);
MenuItem detailsMenuItem = new MenuItem("Show Details");
detailsMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
MenuItem editMenuItem = new MenuItem("Edit Item");
editMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
MenuItem deleteMenuItem = new MenuItem("Delete Item");
deleteMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
public void onClick(MenuItemClickEvent event) {
}
});
itemListMenu.setData(detailsMenuItem, editMenuItem, deleteMenuItem);
RootLayoutPanel.get().add(itemListMenu);
}
Everyrything is fine, the width without doing anything correspond to the length of the longest item. So to which container did you add your menu?.

Blackberry Bitmap fieldChanged throws IllegalStateException

I have a bitmap field in my blackberry5 app with fieldChanged listener attached to it which works absolutely fine
now my problem is that I also have an associated menu for the same purpose (I can not remove it's the requirement) and on click the menu I get a JVM 104 IllegalStateException
here is my menu class
public class TabMenu extends MenuItem{
MainScreen menuScreen;
Field button;
public TabMenu(String menuLabel,MainScreen menuScreen,Field button)
{
super(menuLabel, 1, 0);
this.menuScreen = menuScreen;
this.button = button;
}//end constructor
public void run()
{
FieldChangeListener listener = (FieldChangeListener)this.menuScreen;
listener.fieldChanged(this.button, this.button.getIndex());
this.button.setFocus();
}
}
and here is menu and fieldchnaged code
protected void makeMenu(Menu menu, int instance) {
menu.add(new RefreshMenu());
menu.addSeparator();
menu.add(new TabMenu("Go >", this, goTab));
menu.addSeparator();
}
public void fieldChanged(Field field, int context) {
if (field == goTab) {
Dialog.alert("goinf")
}
}
Try changing your TabMenu#run() method to the following:
public void run() {
this.button.fieldChangedNotify(this.button.getIndex());
this.button.setFocus();
}

Blackberry delete menu item

I have mainscreen with 5 menus and after a certain action I need to delete 2 of them in a method that peforms the action, can I delete menu items programetically ?
Run this sample code:
public class Abc extends MainScreen
{
ButtonField click;
MenuItem saveMenu;
public Abc()
{
createGUI();
}
private void createGUI()
{
saveMenu=new MenuItem("Save", 100, 101);
addMenuItem(saveMenu);
click=new ButtonField("click");
click.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
removeTheMenu(saveMenu);
}
});
add(click);
}
public void removeTheMenu(MenuItem menuItem)
{
Screen screen=Ui.getUiEngine().getActiveScreen();
Menu menu=screen.getMenu(0);//Gives the Menu list of active screen only;
for(int i=0;i<menu.getSize();i++)
{
if(menu.getItem(i).toString().equalsIgnoreCase(menuItem.toString()))
{
removeMenuItem(menuItem);
Status.show("Removed Successfully", 1000);
}
}
}
}
This code may help you;

create custom menu on blackberry

I create a custom menu in new class extends popupScreen. I went when the user clock on the menu button the menu display. I use this code
protected boolean keyDown(int keycode, int time) {
if(Keypad.KEY_MENU == Keypad.key(keycode))
{
UiApplication.getUiApplication().popScreen(getScreen());
Menu popup = new Menu();
UiApplication.getUiApplication().pushScreen(popup);
return true;
}
else
return super.keyDown(keycode, time);
}
but I obtain error on this line UiApplication.getUiApplication().pushScreen(popup); causes by pushScreen. How can I change this code or there is another method to display this menu.
try this
protected boolean keyDown(int keycode, int time) {
if(Keypad.KEY_MENU == Keypad.key(keycode))
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(getScreen());
Menu popup = new Menu();
UiApplication.getUiApplication().pushScreen(popup);
}
return true;
}
else
return super.keyDown(keycode, time);
}
In Blackberry, creating, displaying and hiding of Menu is handled by the system; you will be provided with callbacks at appropriate time. The callbacks you will need to code are:
public boolean onMenu( int instance )
{
return true; // Menu is created
}
public void makeMenu( Menu menu, int instance )
{
MenuItem _desired_menu_item = new MenuItem()
{
public void run()
{
}
}
menu.add( _desired_menu_item );
super.makeMenu( menu, instance)
}
That's it! It would work. Please check Blackberry "UI and Navigation guide" for more details

Resources