Android Xml File Button Hidden - android-layout

In My Android Application, i have to hide button based on some condition,if condition is true than button is hide,otherwise it appear as it is, so for hide facility i'm using button's buttonID.setVisibility(View.INVISIBLE),so that button is hidden but it take space in xml file,so please suggest me to button is hidden and don't take space in xml file

visible - This means visible and it takes space.
invisible- This means invisible and it takes space.
gone- This means invisible and it DOESN'T takes space.
Use it as follows:
Visible tag in XML
android:visibility="visible"
Visible code in java
view.setVisibility(View.VISIBLE);
Invisible tag in XML
android:visibility="invisible"
Invisible code in java
view.setVisibility(View.INVISIBLE);
Gone tag in XML
android:visibility="gone"
Gone tag in java
view.setVisibility(View.GONE);

you should use View.GONE instead of View.INVISIBLE

As what #Tim suggested,you can always change the layout parameters for the elements not just set it's visibility to VISIBLE or GONE
Here the sample. Assume checkBox is clicked
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
buttonID.setVisibility(View.GONE);
}
else{
buttonID.setVisibility(View.VISIBLE);
// now settings the new parameters
AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) buttonID.getLayoutParams());
params.x = 100; // the new value
params.y = 100; // the new value
buttonID.setLayoutParams(params);
}
});
Source : Android: how to change layout_x, layout_y in an AbsoluteLayout dynamically?

Related

Is this a bug in the Tab Container?

I think this is a bug in the Tab Container...
Opening a new tab using Java or the Server Side JavaScript createTab method when the new tab contains a panel that is set to be an iframe pointing to another XPage in the same database will always cause the XPage to get reloaded after loading about five or six tabs (in Chrome, IE does the same but it takes more tabs...)
If the tab contains an iframe that points to another database that holds the XPage it works fine.
The SSJS code is:
getComponent("djTabContainer1").createTab({title:"New tab"});;
The Java code is
public static boolean createTab(UIDojoTabContainer tabContainer) {
try {
if (tabContainer == null) {
tabContainer = (UIDojoTabContainer) Utils.findComponent("TabContainer");
if (tabContainer == null) {
return false;
}
}
String tabTitle = null;
String url = null;
String unid = null;
UIDojoTabPane newTab = null;
// get default number from current project preferences
tabTitle = "My Tabpage";
url = Utils.GetXpageURL("tabpage.xsp");
// create a new Tab
newTab = new UIDojoTabPane();
newTab.setTitle(tabTitle);
newTab.setTabUniqueKey(new Random().toString());
newTab.setClosable(true);
newTab.setId("TabContainer_" + unid);
newTab.setStyleClass("myTabContainer");
Utils.WriteToConsole("setting style class on " + newTab.getTitle());
// newTab.setStyle("height:auto;width:auto; overflow-y: auto;border: 0px;");
// create new Panel
UIPanelEx newPanel = new UIPanelEx();
newPanel.setId("IFrame" + unid);
newPanel.setStyleClass("iframeClass");
// make an iFrame of this panel with our URL as src
newPanel.setTagName("iframe");
Attr property = new Attr();
property.setName("src");
property.setValue(url);
newPanel.addAttr(property);
// add Panel to our new Tab
newTab.getChildren().add(newPanel);
// add the new tab to our tab container
tabContainer.getChildren().add(newTab);
tabContainer.setSelectedTab(unid);
return true;
} catch (Exception ex) {
Utils.WriteToConsole("Unable to add a new Tab Page to the Tab Container (com.tlcc.Main.createTab)", ex);
return false;
}
}
The XPage that is referenced in the src property of the iframe is very basic...
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button
value="Label"
id="button1">
</xp:button>
<xp:inputText id="inputText1"></xp:inputText></xp:view>
When the XPage reloads it has no more tabs (except the first tab that was created in the XPage at the start) and is not responsive.
Howard
It could be a server page persistence/component tree limit problem. If you use the default server page persistence, the server only stores 4 pages in memory (per user).
When you create new tabs on the page that loads another XPage, the server is filling up the server page persistence queue and when you hit the 5th tab, the current page is no longer part of the server page persistence (the component tree is no longer in memory) leading to a reload of the current page.
You can increase the number of pages stored (and also move the disk persistence instead of memory persistence). You can also set viewState to "nostate" on the XPage that you load in the iframe (at least to test out my theory).
See Toby Samples blog post on state and this answer on a similar state issue: https://stackoverflow.com/a/31431917/785061
So, to finalize this... the setting for viewstate=nostate allows more tabs but then does not keep the components in memory. So, it works well for readonly XPages but not when the document on the XPage is in edit mode. The setting Maximum Pages on disk in the Xsp properties on the persistence tab will allow more tabs with iframes that have XPages but still will crash at some point.
Net is, don't use multiple iframes that pull in XPages from the same nsf...

Scroll to the selected tab if the selected tab is hidden in p:tabview on initial tabview load

Assume that there are many tabs are there in p:tabview and scroll is being shown to navigate to all the tabs.
If the active tab whose contents are shown is the right most tab then it is not visible to the user on initial p:tabview load. If we navigate to the right most using scroll button then we could see the active tab highlighted indicating it is selected tab.
How to scroll to the active tab on load so that user able to see the selected tab always.
This can be done in the following way by overriding initScrolling method in primefaces p:tabview component JavaScript file i.e. tabview.js file.
initScrolling: function() {
if(this.jq.is(':visible')) {
var overflown = (this.lastTab.position().left - this.firstTab.position().left) >
this.navscroller.innerWidth();
if(overflown) {
this.navscroller.css('padding-left', '18px');
this.navcrollerLeft.show();
this.navcrollerRight.show();
activeTab = this.navContainer.children('.ui-tabs-selected');
viewportWidth = this.navscroller.innerWidth();
activeTabPosition = activeTab.position().left + parseInt(activeTab.innerWidth());
if(activeTabPosition > viewportWidth) {
var scrollStep = activeTabPosition - viewportWidth;
scrollStep = Math.ceil(scrollStep/100) * -100;
this.scroll(scrollStep);
} else {
this.restoreScrollState();
}
}
return true;
}
else {
return false;
}
}
I would have wished to override this single method by extending tabview component widget but it is not supported. So we should have our own tabview.js file with the above method modified.
This is done in primefaces 4.0 version, more, or less the changes will be same higher versions also.

GWT-Boostrap3 Dropdown, Dropdownmenu widgets do not have changehandler

Currently I am using GWT-bootstrap3 dropdown and dropdownmenu widgets. These widgets are in uibinder.xml file. In .java file, I am not able to handle change event on these widgets.
For example, If i select different options from dropdown, I need to have selected option. How to handle onselection change event in GWT-bootstrap3 dropdown widget?? Please share ideas..
Thanks
You can use AnchorListItem inside DropDownMenu, then you can addClickHandler to AnchorListItem objects.
In UI binder XML:
<b:DropDownMenu ui:field="menuUserInfo" addStyleNames="wt-dropdown-menu">
<b:AnchorListItem ui:field="menuItemPreferences" text="Preferences"/>
<b:AnchorListItem ui:field="menuItemLogout" text="Logout"/>
</b:DropDownMenu>
In Java code:
menuItemLogout.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent clickEvent) {
// Added logout logic
}
});

LWUIT move all commands from the form to the "slide context menu"

I am trying to make a calculator for nokia 501 asha and i want all my buttons to fit on the the screen so that i don't have to scroll the form to access all buttons.
Apparently adding commands like exit,about and help are mandatory to your app.
Now when i add these commands one of the commands appear as a button and occupy a lot of screen space which i don't want.
I want my commands to appear like this i.e all commands on the slide context menu.
But instead there's an unnecessary button on the screen.
The code that i have used to add commands is as follows:
Form a = new Form("form");
a.addCommand(new Command("exit"),0);
a.addCommand(new Command("HELP"),1);
a.addCommand(new Command("ABOUT"),2);
a.setEnabled(true);
a.show();
So, what modifications i need to make in that code so that all my commands appear on the slide context menu ?
I am looking the Asha UI Component Demos, in the Menu section, options menu. I find this code to add the Commands:
// The rest appear in menu
Command menuCommand1 = new Command("Command 2", Command.SCREEN, 1);
addCommand(menuCommand1);
Command menuCommand2 = new Command("Command 3", Command.SCREEN, 2);
addCommand(menuCommand2);
Command menuCommand3 = new Command("Command 4", Command.SCREEN, 3);
addCommand(menuCommand3);
Try to put this Command.SCREEN parameter.
This answer will help to someone. The following code is working in 501.
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Display.init(this);
// For hide the form title bar. It is working in Nokia asha 501.
Display.getInstance().setForceFullScreen(true);
Display.setObjectTrait(Display.getInstance().getImplementation(), "nokia.ui.canvas.status_zone", Boolean.TRUE);
Form a = new Form("form");
a.addCommand(new Command("exit"),0);
a.addCommand(new Command("HELP"),1);
a.addCommand(new Command("ABOUT"),2);
a.setEnabled(true);
a.show();
}

Selection type changes context menu using chrome extension

I am trying to build a chrome extension. In it I want the context menu to change according to the selected text on the page.
For example, if its a number I want a menu that says divisibility test for this numbr is ...
and if it is a string, it should have a something else, but not both at the same time.
I cant figure out how to do that.
You will have to set a listener for mouse down. There is no other way to get the selected text before the menu is created.
See this SO question:
chrome extension context menus, how to display a menu item only when there is no selection?
Here is part of the code the rest is at the link.
document.addEventListener("mousedown", function(event){
//right click
if(event.button == 2) {
if(window.getSelection().toString()) {
chrome.extension.sendRequest({cmd: "createSelectionMenu"});
} else {
chrome.extension.sendRequest({cmd: "createRegularMenu"});
}
}
}, true);

Resources