Sunday, July 8, 2012

How to create context menu in Android

Following steps required to create Context menu in android application. When user click long on any item present on the screen, we usually show option in terms of context menu.


  1. Register View for context menu.
  2. Prepare menu items.
  3. Define action on selecting the menu item.



Context menus are bind with the view, you need to get the view and register for context menu as shown following.



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t=(TextView)findViewById(R.id.textView);
registerForContextMenu(t);
}



Prepare Menu Items


Override the "onCreateContextMenu" method of Activity class.

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Hello");
// Assuming that you already have an array in your string.xml
String[] menuItems = getResources().getStringArray(R.array.menu_options);
for (int i = 0; i < menuItems.length; i++) {
menu.add(Menu.NONE, i, i, menuItems[i]);
}
}


Define Action on selecting the menu item.


Override the "onContextItemSelected" method of Activity Class.

public boolean onContextItemSelected(MenuItem item) {
Toast.makeText(this, "Context menu item " + item.getItemId(), Toast.LENGTH_LONG).show();
return super.onContextItemSelected(item);
}




Landing page of the application



Long click on Hello World Text View



On Click at add menu item


Monday, June 25, 2012

jQuery autoComplete view all on click


$(function() {
    $('#id').autocomplete({
        source: ["option1","option2","option3"],
        minLength: 0
    }).click(function(){     
       $(this).autocomplete('search',"");
    });
});

Wednesday, July 21, 2010

Model Window with Javascript and css

This code is tested on following browsers.
  • IE6
  • IE7
  • IE8
  • Firefox
  • Safari

Code.
<style type="text/css"> body { margin: 0px; } #modalPage { display:
none; position: absolute; width: 100%; height:
100%; top: 0px; left:
0px; } .modalBackground { filter: Alpha(Opacity=40); -moz-opacity:0.4;
opacity: 0.4; width: 100%;
height: 100%; background-color:
#999999; position: absolute; z-index: 500; top:
0px; left: 0px; } .modalContainer { position:
absolute; width: 300px; left: 50%; top:
50%; z-index: 750; } .modal { background-color: white; border:
solid 4px black;
position: relative; top: -150px; left:
-150px; z-index: 1000; width: 300px; height:
300px; padding: 0px; } .modalTop { width: 292px; background-color:
#000099; padding: 4px; color: #ffffff; text-align:
right; } .modalTop a, .modalTop
a:visited { color: #ffffff; } .modalBody { padding: 10px; } </style> <div
id="modalPage"> <div class="modalBackground"> </div> <div class="modalContainer"> <div
class="modal"> <div class="modalTop"><a href="javascript:hideModal('modalPage');void(0);">[X]</a></div> <div
class="modalBody"> <p>total solid</p> </div> </div> </div> </div> <script language="javascript"
type="text/javascript"> function revealModal(divID) { window.onscroll =
function () {
document.getElementById(divID).style.top = document.body.scrollTop;
}; document.getElementById(divID).style.display = "block"; document.getElementById(divID).style.top
= document.body.scrollTop; } function hideModal(divID) { document.getElementById(divID).style.display
= "none"; } </script> <input id="Button1"
type="button" value="Click here
to be test
model" onclick="revealModal('modalPage')" />

Monday, July 12, 2010

Ajax request in Prototype

Here is the code for making ajax request in prototype.



new Ajax.Request(urlToAccess, {
method: 'get',
onSuccess: function(transport) {


},
onFailure: function(transport) {


}
});

Tuesday, July 6, 2010

Steps for Paying income tax online for non govt employee.

  1. Log on to incometaxindia.gov.in.
  2. On the left hand side of the page select "PAY TAXES ONLINE"
  3. A new page will open up with a list of all the banks through which payment can be made online. Just below this list is a link "Please click here". Click on this link.
  4. Select Challan No. 280 on the next Page.
  5. Please fill the Challan that appears. In the two option box sets on the page, you need to select "(0021) INCOME-TAX(OTHER THAN COMPANIES)" in one set and "(300) SELF ASSESSMENT TAX" in the other. You need to select Assessment Year as current year.
  6. Once you click on Proceed, the system will verify your PAN no. in the Income Tax Database.
  7. Click on Submit to the Bank and complete the transaction with the bank.