Thursday, October 29, 2009

Event Handling In Android


In my previous article I discussed about how to create user interfaces in Android. Here I’m going to show you how you can add event handler to that UI. To do that, first add these two lines between package and class declaration.
import android.view.View;
import android.widget.Button;
Now replace your onCreate method using following code.
import android.view.View;
import android.widget.Button;

public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.testview);
 Button ok = (Button)findViewById(R.id.btn_testview_ok);
 ok.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v){
   moveToMain();
  }
 });
}
private void moveToMain() {
 // TODO Auto-generated method stub
 setContentView(R.layout.main);
}
In the above code "btn_testview_ok" is the id of the "Ok" button in previous article. When you click that button, the moveToMain(); method will be called and content view will changed as "main.xml". I will discuss more about this topic in my next posts.

Android User Interface Design


In one of my previous post I discussed about Creating Android Databases. In this tutorial I’ll discuss simple way to create Android UI using Eclipse and DroidDraw tool which support drag-and-drop of widgets like buttons, labels, text boxes, etc.

Displaying the user interface is done by Activity, the fundamental unit of an Android application. The setContentView() method of the Activity class load the XML UI located in the res/layout folder in the onCreate() event.

An Activity has Views and ViewGroups. Here View is a widget and collection of one or more View can be considered as ViewGroup. ViewGroup plays a major role by providing us layout to arrange the appearance and sequence of views. Well, let’s built our first User Interface in Android.

1. First create simple Android project.

2. Then using DroidDrow design your interface (show steps) and click "Generate" button at the top left corner.

First open DroidDrow and select AbsoluteLayout because using that layout you can easily place widgets as you want.



Then drag–and-drop widgets you want to the design surface.



You can change properties of your widgets using "Properties" tab. There if you want to change the Id, change the things after "@+id/".



Finally click "Generate" button to get the XML code to the "output" textbox.



3. Now add new XML file to "layout" folder as follows. There I’ll give the file name as "testview.xml". Don’t use capital letters for the name.





4. Then click on "testview.xml" tab and replace existing code by generated code from the DroidDrow tool.



5. Now replace the "setContentView(R.layout.main);" using "setContentView(R.layout.testview);". Now your "onCreate" method should appear as follows.

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.testview);
}

Finally save all and run the project to see your interface in Android.



If you are interested please refer Event Handling in Android to learn how to handle events for these widgets.

Tuesday, October 27, 2009

Add META Tags To Blogger


META tags provides information about a web page such as who created the page, what the page is about and which keywords represent the page content. They do not affect how the page is displayed. Many search engines use this information when building their indices.

By default blogger does not contain META tags. In this tutorial I’m going to tell you how you can add META tags to your blog without causing problems. If you simply add these tags you will get "Duplicate meta descriptions" HTML suggestion as following picture.



Let’s see how we can add these tags without causing problems.

1. First log into your blog and from dashboard go to the "Layout --> Edit HTML" page as follows;



2. Then locate the <b:include data='blog' name='all-head-content'/>, you can find it between <head > and </head> tags as following picture;



Then paste this code just after that code.
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<meta content='Insert description here' name='description'/>
<meta content='Insert your keywords here' name='keywords'/>
<meta content='Insert Your Name' name='author'/>
</b:if>
Description : Limit it for maximum 200 characters.

Keywords : Do not repeat more than three times. The maximum number of keywords we recommend for this tag is 20.

Monday, October 26, 2009

Blogger Post Title Tip (SEO)


By default in blogger the blog title appears first before appear your post title. If you consider Search Engine Optimization (SEO) that is not a good practice. In this tutorial I’m going to show you how to make the blogger post title come first as following picture.



You can follow these simple steps to swap the title and post title in blogger for a better Search Engine Optimization.

1. First log into your blog and from dashboard go to the "Layout --> Edit HTML" page as follows;



2. Then locate the <title><data:blog.pageTitle/></title>, you can find it between <head > and </head> tags as following picture;



3. Then replace that code by following code; It is always good if you download the Full Template before editing.
<b:if cond='data:blog.pageType == "index"'>
<title><data:blog.title/></title>
<b:else/>
<title><data:blog.pageName/> | <data:blog.title/></title>
</b:if>
Finally save template and you will see the result immediately in your browser title and after few days in search results.

Saturday, October 24, 2009

Expandable Blogger Posts


This tip can be used in your blog or web site to hide long posts or articles. Inserted of navigating to another page, using this tip you can wrap things like screen shots and source codes that reader doesn’t want to see at the page load.

Bellow is the demo of what we are going to do. Click the "Show All" link to unhide the things. You may notice without a page refresh you can simply get your work done.

Show All

Note: This text was hidden; you have unhide it by clicking "Show All". If you want to hide this note, then click the "Show All" link again.

Now let’s see how we can do this;

First paste this code between <head> and </head> tags in your HTML code. To see how you can do it in blogger click here.

1.First go to "Edit HTML" page,



2.Then find the <head> and </head> tags,

<style type='text/css'>
 .commenthidden {display:none}
 .commentshown {display:inline}
</style>
<script type='text/Javascript'>
function togglecomments (postid) {
 var whichpost = document.getElementById(postid);
 if (whichpost.className=="commentshown") {
  whichpost.className="commenthidden"; }
 else { whichpost.className="commentshown"; 
 }
}
</script>
Then as bellow I have Add the "Show All" link before add the content I'm going to hide ;
<a aiotitle="click to expand" href="javascript:togglecomments('yourDivId')">Show All</a>
Then put the things that you want to hide between

<div class="commenthidden" id="yourDivId"> and </div>

In the above example I did it as bellow;
<div class="commenthidden" id="yourDivId">
Note: This text was hidden; you have unhide it by clicking "See All". If you want to hide this note, then click the "See All" link again.
</div>
Note: Here "yourDivId" should be unique one. That means if you are going to use this more than one time, you have to replace "yourDivId" using unique name.

Wednesday, October 14, 2009

Sort Object ArrayList in C#


You can easily sort an arraylist using its "sort()" method, but how can you sort an ArrayList of Objects? You can get this task done very easily with "IComparer" Interface.

As an example let’s get a "Person" object which contains two attributes called "ID" and "Name". Now we need to sort these objects by "ID" or "Name". By looking at the following picture, you can get very clear idea about what we are going to do now.



You may notice in "Sort 2" first I have sort by "ID" and then by "Name". I’ll give you the C# code for the above task using simple console application.

Create new class called "Person" and paste this code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SortArrayList
{
    class Person
    {
        private int id;
        public int ID
        {
            get { return id; }
            set { id = value; }
        }
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public int CompareTo(Person psn2, ObjCompare.ComparisonType comparisonType, Person psn1)
        {
            int returnValue;
            if (comparisonType == ObjCompare.ComparisonType.ID)
            {
                if (psn1.ID == psn2.ID)
                {
                    returnValue = Name.CompareTo(psn2.Name);
                }
                else
                {
                    returnValue = ID.CompareTo(psn2.ID);
                }
            }
            else if (comparisonType == ObjCompare.ComparisonType.Name)
            {
                returnValue = Name.CompareTo(psn2.Name);
            }
            else
            {
                returnValue = ID.CompareTo(psn2.ID);
            }
            return returnValue;
        }
    }
}
Create new class called "ObjCompare" and paste this code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SortArrayList
{
    class ObjCompare : IComparer
    {
        public enum ComparisonType
        {
            ID, Name
        }
        private ComparisonType compMethod;
        public ComparisonType ComparisonMethod
        {
            get { return compMethod; }
            set { compMethod = value; }
        }
        public int Compare(object x, object y)
        {
            Person psn1 = (Person)x;
            Person psn2 = (Person)y;
            return psn1.CompareTo(psn2, ComparisonMethod, psn1);
        }
    }
}
Now update your "Programme.cs" as bellow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SortArrayList
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList lst = new ArrayList();

            Person psn = new Person();
            psn.Name = "Jack"; psn.ID = 15;
            lst.Add(psn);

            Person psn1 = new Person();
            psn1.Name = "David"; psn1.ID = 18;
            lst.Add(psn1);

            Person psn2 = new Person();
            psn2.Name = "Daniel"; psn2.ID = 12;
            lst.Add(psn2);

            Person psn3 = new Person();
            psn3.Name = "Owen"; psn3.ID = 20;
            lst.Add(psn3);

            Person psn4 = new Person();
            psn4.Name = "Colin"; psn4.ID = 16;
            lst.Add(psn4);

            Person psn5 = new Person();
            psn5.Name = "Aiden"; psn5.ID = 18;
            lst.Add(psn5);

            Console.Write(" ---before sort --- \n");
            foreach (Person item in lst)
            {
                int id = item.ID;
                string ttl = item.Name;
                Console.Write(id + " " + ttl + "\n");
            }
            /* sorting */
            ObjCompare objcom = new ObjCompare();
            objcom.ComparisonMethod = ObjCompare.ComparisonType.ID;
            lst.Sort(objcom);

            Console.Write(" ---after sort -- \n");
            foreach (Person item in lst)
            {
                int id = item.ID;
                string ttl = item.Name;
                Console.Write(id + " " + ttl + "\n");
            }
        }
    }
}
You will get the output as "Sort 2" in the picture. If you don't want to sort by "Name" you can do it by editing "Person" class. There I have check whether "psn1.ID == psn2.ID", by commenting that part you can get the result as "Sort 1".

Monday, October 12, 2009

Hide Columns in SharePoint Part 2


Note : Before going to use this method you have to make sure all the columns are added to the list.Otherwise you have to remove the added custom form the SharePoint Designer (described in the post) and add it again after adding new column. It is better to use this way if you want hide and change control modes of fields. Also keep in mind to add at least one list item before use this method.

You can try SharePoint Tips Utility Pack if you are not sure whether you need to add columns in future or not.


In the first part of this post I discussed how to hide a column in SharePoint list. By using "Content Types" you cannot hide column in single form. Here I’m going to discuss how you can hide a column only in one (Edit, Display or New) mode using Microsoft SharePoint Designer 2007.

As an example I’m going to use the “Tasks” list and there I’ll remove “Due Date” column in Edit Mode.

First open your site using Microsoft SharePoint Designer 2007 as in Figure 1 (File --> Open Site…, in Site Name field give URL to your site without “default.aspx”. e.g. http://mysite:5050/testsite).



Then double click the displaying window and mark the "layout" hidden as in figure 2.



Then click once on area 1(Figure 3) and insert your custom list form. There select “Tasks” and “Edit item form”, because we are going to change the edit form of task list (Figure 4).





Then select the row you want to hide and comment the HTML code (Figure 5).



Further if you want to display the raw in edit mode and you don’t want to allow editing it, you can change the Control mode property (Figure 6).



There keep in mind you can change control mode, if the column is not default one. That mean, to change the control mode using SharePoint Designer, you have to create your own column using "Settings –> Create Column".



Now save all and see, you will see the "Due Date" column is hidden and you cannot edit Test Col column (Figure 7).

Hide Columns in SharePoint Part 1


In SharePoint lists, sometimes we have to use hidden columns for our programming purposes. In this tutorial I’m going to discuss, how you can hide a column in SharePoint.

First let’s see how to hide a column in any list view. Here you should have permission to see some menus, if you cannot see them; you have to contact your administrator.

Open your list and go to List Settings (Figure 01).



At the bottom of the page select your view, which you want to hide a column (Figure 02). I'm going to select "All Items" view.



Then unmark all columns you want to hide in that view and click OK (Figure 03).



Now you can see, unmarked columns are not shown in "All Items” view.

Note : By selecting manage content type item in list settings, you can hide a column in New, Edit and Display forms. To do that go to the content type item and select the field you want to remove from your forms. Then choose “This column is hidden (will not appear in forms)”.

To hide a column in New, Edit or Display mode using Microsoft SharePoint Designer 2007 please refer second part of this post.

Tuesday, October 6, 2009

Delete item from SharePoint List


In my previous post SharePoint List C# Part 1 I discussed how we can add items to SharePoint list. We also have to delete items from a list. Following C# code can be used in your custom webpart or feature to delete item from SharePoint list. Here I am going to find the items to delete using CAML query.
public void  DeleteListItem()
{
 // choose your site
 string strUrl = "http://mysite:5050/";
 using (SPSite site = new SPSite(strUrl))
 {
  using (SPWeb web = site.OpenWeb())
  {
   SPList list = web.Lists["List_A"];
   SPListItemCollection itemCollection;
 
   SPQuery oQuery = new SPQuery();
   oQuery.Query = "<where><eq><fieldref Name='Title' /><value Type='Text'>ABC</Value></Eq></Where>"; 
   itemCollection = list.GetItems(oQuery);
 
   List<splistitem> valuesToDelete = new List<splistitem>();
 
   foreach (SPListItem item in itemCollection)
   {
    valuesToDelete.Add(item);
   }
   web.AllowUnsafeUpdates = true;
   foreach (SPListItem itm in valuesToDelete)
   {
    itm.Delete();
   }
   list.Update();
   web.AllowUnsafeUpdates = false; 
  }
 }
}
In the above example I have use a CAML query to delete items in the Task list which title equal to ABC. As above you have to maintain separate list to stote items that you are goint to delete, otherwise it will not work.

Monday, October 5, 2009

What is SharePoint ?


SharePoint, the fastest-growing product in the history of Microsoft is a collection of products and software elements which can be configured to run Intranet, Extranet and Internet sites.

WSS stands for Windows SharePoint Services and it is light document management system which helps you to organize your documents inside your organization using file sharing and intranet. MOSS stand for Microsoft SharePoint server and it contain all the things in WSS and more advanced things like people search, workflows, site templates and business intelligence.



There are many applications like Portals, Content Management, Indexing, Search, Business Intelligence and Collaboration built in to SharePoint and Sites, Pages, Lists, Libraries and webparts can be considered as building blocks.

SharePoint most commonly use as intranet portals and it allow users to login to their intranet web site and see the information like announcements and news. Using SharePoint you can build a collaboration environment quickly and easily. That will improve team productivity while managing documents and ensuring integrity of content.

Friday, October 2, 2009

CAML & SPQuery in SharePoint


Using Collaborative Application Markup Language (CAML)  queries with SPQuery and SPSiteDataQuery is a faster and more efficient way of retrieving items based on known criteria compare with for each on the SPListItemsCollection and checking for the criteria.

In this tutorial I’m going to discuss how you can write CAML queries for retrieving items in SharePoint List.

Operators

These are some common operators you can use with CAML queries.

  1. Eq--Equals
  2. Neq--Not equal
  3. Gt--Greater than
  4. Geq--Greater than or equal
  5. Lt--Lower than
  6. Leq--Lower than
  7. IsNull--Is null
  8. BeginsWith--Begins with
  9. Contains--Contains

Get All Items

This is discussed in SharePoint List C# Part 1. There you can write the query as follows. There you can get all the items in the list.

myquery.Query = "";

Single Criteria

Using following query you can get all the tasks where “ID” is equal to 5.
<Where>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>5</Value>
</Eq>
</Where>
You can get Value Types for different common type of columns using following list

e.g. Use Value Type "Text" for column type "Single line of text".

  1. Single line of text--Text
  2. Multiple lines of text--Note
  3. Choice (menu to choose from)--Choice
  4. Number (1, 1.0, 100)--Number
  5. Date and Time--DateTime
  6. Lookup (information already on this site)--Lookup/LookupMulti
  7. Yes/No (check box)--Boolean
  8. Person or Group--User

Using AND

This will give you the items where ID = 5 and Title =  "ABC".
<Where><And>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>5</Value>
</Eq>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>ABC</Value>
</Eq>
</And></Where>
OR

This will give you the items where ID = 5 or Title =  "ABC"
<Where><OR>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>5</Value>
</Eq>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>ABC</Value>
</Eq>
</OR></Where>
It is different if you want to use more than one "AND" or "OR" operator. As a example if you want to get items where ID = 5 and Title = "ABC" and created by "John", then you can write this.
<Where>
<And>
<And>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>5</Value>
</Eq>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>ABC</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Author' />
<Value Type='User'>John</Value>
</Eq>
</And>
</Where>
To get the correct FieldRef Name write accurate queries you can use U2U CAML Query Builder.

Remember though you rename a column the FieldRef Name will hold same value.

SharePoint User Groups


Check User Group in SharePoint

To store and manage permissions we can create User Groups in SharePoint. In this article I’ll discuss how you can check whether the current user is in a particular group using C#. This method will return Boolean value "true" if the user in the given group. You can use this method in your custom webpart.
        public bool isMemberInGroup(string groupName)
        {
            string siteUrl = "http://mysite:5050/";
            SPSite site = new SPSite(siteUrl);
            SPWeb web = site.OpenWeb();

            bool memberInGroup = web.IsCurrentUserMemberOfGroup(web.Groups[groupName].ID);

            return memberInGroup;
        }
If you want to compare the current user in "Person or Group" column type, then you can also get the current user’s user name using  "web.CurrentUser.Name".

Thursday, October 1, 2009

Deleting Features from SharePoint


In one of my previous article I discussed about creating and deploying custom features to SharePoint server. Here I’m going to describe how you can remove a feature from SharePoint.

First log into your server and go to SharePoint central administration site (Figure 1).


Then move to “Operations” tab and select "Solution management" (Figure 2).

Now you can select the feature that you want to remove. If it its status is "Not Deployed", you can simply click "Remove Solution" (Figure 4) and for the “Deployed” solutions first you have to click “Retract Solution” (Figure 3) and then remove.


To me it didn’t work when I remove my solution and redeploy using same name.

Related Posts :

Related Posts with Thumbnails