Wednesday, 29 January 2014

Create table with border in android

Create table with border in android

Table Layout:

According to the Android developer guide, border lines are not displayed for table layouts. However, often you will find the need to do things such as having vertical separators between table cells and borders around table rows.

Give the TableLayout a background color, give the TableRow another background color and set margin to the TableRow. The amount of the margin is the amount of the “border”. Same for each View in the TableRow.

Code:


We can create table with border. Consider the following main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<TableLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*" android:background="#ff0000">
<TableRow 
          android:background="#00ff00" 
          android:layout_margin="2dip">
<TextView 
         android:text="1st Column"
          android:background="#0000ff"
          android:layout_margin="2dip"/>
<TextView 
             android:text="2nd Column" 
            android:background="#0000ff"
            android:layout_margin="2dip"/>

<TextView 
            android:id="@+id/amount" 
            android:background="#0000ff"
            android:layout_margin="2dip" 
            android:text="3rd col"/>
</TableRow>
</TableLayout>

Now the activity code is below:

Code:

package sample.my.tablelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;

public class Article_androidActivity extends Activity 
{

  @Override
      public void onCreate(Bundle savedInstanceState) 
       {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.main);
        }
}

Monday, 27 January 2014

ListView in android

Insert ListView in Android App

ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

XML file


<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
   <ListView
       android:id="@+id/att_listView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
     >
     </ListView>       
  </LinearLayout>

Java FIle    


import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Listview extends Activity {

ListView listview;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);

//Initialize ListView
listview=(ListView)findViewById(R.id.att_listView);
//ADd Items in List View
ArrayList<String> list=new ArrayList<String>();
list.add("Apple");
list.add("Banana");
list.add("Orange");
list.add("other Fruits");

//Bind list View to Array Adapter to List and Default list View
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,list);
//set Adapter to ListView
listview.setAdapter(adapter);
//ListView onClick Listener
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View arg1, int position,long id)
{
// what ever you want to perform
String item=String.valueOf(adapter.getItemAtPosition(position));
Toast.makeText(getApplicationContext(), item, Toast.LENGTH_SHORT).show();
}
});
}
}

Output

Saturday, 25 January 2014

Install PHP on windows xp/7/8

Installing PHP on windows

Introduction of PHP

Rasmus Lerdorf wrote the first PHP - first called Personal Home Page - scripts as a series of Perl scripts that he used to track visitors to his webpage and to see who was viewing his resume. He eventually rewrote PHP as a scripting engine and added support for forms. Over the years the Personal Home Page acronym was dropped and it evolved into the PHP Hypertext. PHP can be used to create web applications ranging from personal websites to e-commerce applications and community web portals i.e. disucssion forums, blogs etc.

Installation Step :


1) Install Apache, Mysql, PHP (AMP):

There are 2 types server available to install AMP on windows
(i) Windows AMP (WAMP)
(ii) XAMPP (common server for all OS)

for windows i advice you to use WAMP server

2) Download WAMP/XAMPP server.


(i) Download  WAMP server from below link


(ii) Download  XAMPP server from below link

(installation step of xampp is same as wamp)

3) Install WAMP server

simply install downloaded file as normal installation.

show version information of AMP.

Select location of installation. keep it as it is.


SMTP settings for EMail services.

4)Test PHP

Check out tray icon will show wampserver icon (which means wamp server install successfully).

pen your browser to navigate to http://localhost. The WAMP welcome page will appear.


 5)Start Programming

  to run php script, please save your all php file in C:\wamp\www (usually).
(you can also change this path later)