Sunday, 1 September 2013
Friday, 12 July 2013
How to set background image in an android application
It's simple to set background image for your android application. Below I have an example code for this as well.
- Create a new android application in Eclipse. (Here I have used 4.2 Jelly Bean version).
- Copy your image file to /res/drawable-mdpi directory.
- Open your layout xml file activity_main.xml and add below line;
BackgroundImage program structure...
activity_main.xml file
android:background="@drawable/android"
Here 'android' is the name of the image without extension
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/android"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Run your application. The image will be applied as background for this layout.
Wednesday, 3 July 2013
Calendar using JSF
1). JSF Calendar Example Structure:
Note: Download below js and css files
1) CalendarControl.css
2) CalendarControl.js
2). index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link href="css/CalendarControl.css" rel="stylesheet" type="text/css">
<script src="js/CalendarControl.js" language="javascript"></script>
</head>
<body>
<f:view>
<h:form>
<h:messages style="color: red;"></h:messages>
<table>
& <h:outputText value="Enter following Information"></h:outputText>
<tr>
<td>
<h:outputText value="Date:-"></h:outputText>
<h:inputText id="name" value="#{Bean.name}" required="true" onclick="showCalendarControl(this);">
<f:validateLength minimum="2" maximum="25"></f:validateLength>
nbsp; </h:inputText>
</td>
</tr>
<tr>
<td>
<h:commandButton id="button" action="result" value="Submit"></h:commandButton>
</td>
</tr>
</table>
</h:form>
</f:view>
</body>
</html>
3). display.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Calendar</title>
</head>
<body>
<f:view>
<table>
<tr>
<td><b>
<h:outputText value=" Selected date is:- #{Bean.name}"></h:outputText></b>
</td>
</tr>
<tr>
<td>
<a href="/JSF_Calendar/faces/index.jsp">Back</a>
</td>
</tr>
</table>
</f:view>
</body>
</html>
4). faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>result</from-outcome>
<to-view-id>/display.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>Bean</managed-bean-name>
<managed-bean-class>com.satyamsoft.in.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
5). Bean.java
package com.satyamsoft.in;
public class Bean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
6). OutPut
Wednesday, 5 June 2013
JSF outputFormat tag example
1). JSF outputFormat tag Example Structure:
2). index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<title>JSF outputFormat example</title>
</head>
<body>
<f:view>
<h:form>
<h3><h:outputText value="h:outputFormat example" ></h:outputText></h3>
<hr>
<h3>Text</h3>
<b><h:outputFormat value="Country 1 : {0}, Country 2 : {1}, Country 3 : {2}" >
<f:param value="INDIA" />
<f:param value="USA" />
<f:param value="ENGLAND" />
</h:outputFormat></b>
</h:form>
</f:view>
</body>
</html>
3). OutPut
JSF selectOneMenu tag example
1). JSF selectOneMenu tag Program Structure:
2). index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<title>JSF selectOneMenu example</title>
</head>
<body>
<f:view>
<h:form>
<h3><h:outputText value="h:selectOneMenu example" ></h:outputText></h3>
<hr>
<h3>Combo Box</h3>
<h:selectOneMenu value="#{selectOneMenu.selectedCountry}">
<f:selectItem itemValue="INDIA" itemLabel="india" />
<f:selectItem itemValue="USA" itemLabel="usa" />
<f:selectItem itemValue="ENGLAND" itemLabel="england" />
<f:selectItem itemValue="AUSTRALIA" itemLabel="australia" />
<f:selectItem itemValue="CANADA" itemLabel="canada" />
</h:selectOneMenu>
<h:commandButton value="Submit" action="result" />
</h:form>
</f:view>
</body>
</html>
3). SelectOneMenu.java
package com.satyamsoft;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="selectOneMenu", eager=true)
@SessionScoped
public class SelectOneMenu implements Serializable{
private static final long serialVersionUID = 1L;
public String selectedCountry="1";
public String getSelectedCountry() {
return selectedCountry;
}
public void setSelectedCountry(String selectedCountry) {
this.selectedCountry = selectedCountry;
}
}
4). result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<body>
<f:view>
<h:form>
<h:panelGrid columns="1">
<h:column>
<h:dataTable value="#{selectOneMenu.selectedCountry}" var="loc" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Selected Country is:" />
</f:facet>
<b><h:outputText value="#{loc}"/></b>
</h:column>
</h:dataTable>
</h:column>
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
5). OutPut
JSF selectManyListbox tag example
1). JSF selectManyListbox tag Program Structure:
2). index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<title>JSF selectManyListbox example</title>
</head>
<body>
<f:view>
<h:form>
<h3><h:outputText value="h:selectManyListbox example" ></h:outputText></h3>
<hr>
<h3>List Box</h3>
<h:selectManyListbox value="#{selectManyListbox.selectedCountry}">
<f:selectItem itemValue="INDIA" itemLabel="india" />
<f:selectItem itemValue="USA" itemLabel="usa" />
<f:selectItem itemValue="ENGLAND" itemLabel="england" />
<f:selectItem itemValue="AUSTRALIA" itemLabel="australia" />
<f:selectItem itemValue="CANADA" itemLabel="canada" />
</h:selectManyListbox>
<h:commandButton value="Submit" action="result" />
</h:form>
</f:view>
</body>
</html>
3). SelectManyListbox.java
package com.satyamsoft;import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="selectManyListbox", eager=true)
@SessionScoped
public class SelectManyListbox implements Serializable{
private static final long serialVersionUID = 1L;
public String[] selectedCountry={"1","2","3"};
public String[] getSelectedCountry() {
return selectedCountry;
}
public void setSelectedCountry(String[] selectedCountry) {
this.selectedCountry = selectedCountry;
}
}
4). result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<body>
<f:view>
<h:form>
<h:panelGrid columns="1">
<h:column>
<h:dataTable value="#{selectManyListbox.selectedCountry}" var="loc" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Selected Country is:" />
</f:facet>
<b><h:outputText value="#{loc}"/></b>
</h:column>
</h:dataTable>
</h:column>
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
5). OutPut
Tuesday, 4 June 2013
JSF selectOneListbox tag example
1). JSF selectOneListbox tag Program Structure:
2). index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<title>JSF selectOneListbox</title>
</head>
<body>
<f:view>
<h:form>
<h3><h:outputText value="h:selectOneListbox example" ></h:outputText></h3>
<hr>
<h3>List Box</h3>
<h:selectOneListbox value="#{selectOneListbox.selectedCountry}">
<f:selectItem itemValue="INDIA" itemLabel="india" />
<f:selectItem itemValue="USA" itemLabel="usa" />
<f:selectItem itemValue="ENGLAND" itemLabel="england" />
<f:selectItem itemValue="AUSTRALIA" itemLabel="australia" />
<f:selectItem itemValue="CANADA" itemLabel="canada" />
</h:selectOneListbox>
<h:commandButton value="Submit" action="result" />
</h:form>
</f:view>
</body>
</html>
3). SelectOneListbox.java
package com.satyamsoft;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="selectOneListbox", eager=true)
@SessionScoped
public class SelectOneListbox implements Serializable{
private static final long serialVersionUID = 1L;
public String selectedCountry="1";
public String getSelectedCountry() {
return selectedCountry;
}
public void setSelectedCountry(String selectedCountry) {
this.selectedCountry = selectedCountry;
}
}
4). result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<body>
<f:view>
<h:form>
<h:panelGrid columns="1">
<h:column>
<h:dataTable value="#{selectOneListbox.selectedCountry}" var="loc" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Selected Country is:" />
</f:facet>
<b><h:outputText value="#{loc}"/></b>
</h:column>
</h:dataTable>
</h:column>
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
5). OutPut
Subscribe to:
Posts (Atom)