Monday, December 2, 2013

OptionMenu+PopUpMenu+ContextMenu+SubMenu

Menu
-------
main.xml
contextmenu.xml
-----------------
main.xml
---------
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        
        android:title="@string/action_settings">
       <menu>  // sub menu
            <item android:id="@+id/create_new"
                  android:title="New" />
            <item android:id="@+id/open"
                  android:title="Open" />
        </menu>
        </item>
    <item
        android:id="@+id/action_music"
        android:orderInCategory="100"
        android:showAsAction="always|withText"
       
        android:title="@string/action_music"/>
    <item
        android:id="@+id/action_game"
        android:orderInCategory="100"
        android:showAsAction="always|withText"
       
        android:title="@string/action_games"/>

</menu>

contextmenu.xml
------------------
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/action_edit"       
        android:title="@string/action_edit"/>
    <item
        android:id="@+id/action_delete"        
        android:title="@string/action_delete"/>
    <item
        android:id="@+id/action_rename"        
        android:title="@string/action_rename"/>

</menu>

MainActivity.java
-------------------


public class MainActivity extends Activity {
Button btn;
ListView lv;
    String[]name={"Android","IOS","Symbion"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 btn=(Button) findViewById(R.id.button1 );
 lv=(ListView) findViewById(R.id.listView1);
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name);
 lv.setAdapter(adapter);
 registerForContextMenu(lv);
 btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getApplicationContext(), v);
   //MenuInflater inflater = popup.getMenuInflater();
   getMenuInflater().inflate(R.menu.contextmenu, popup.getMenu());
   popup.show();
}
});
 
 
}


@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.contextmenu, menu);
}



@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.action_edit:
Toast toast=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 50, 50);
toast.show();
break;
case R.id.action_delete:
Toast toast1=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast1.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast1.show();
break;
case R.id.action_rename:
Toast toast2=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast2.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast2.show();
break;
}
return super.onContextItemSelected(item);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.action_settings:
Toast toast=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 50, 50);
toast.show();
break;
case R.id.action_music:
Toast toast1=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast1.setGravity(Gravity.CENTER_HORIZONTAL, 50, 50);
toast1.show();
break;
case R.id.action_game:
Toast toast2=Toast.makeText(getApplicationContext(), item.getTitle() , Toast.LENGTH_SHORT);
toast2.setGravity(Gravity.CENTER_HORIZONTAL, 50, 50);
toast2.show();
break;
}
return super.onOptionsItemSelected(item);
}
}


Sunday, December 1, 2013

Setting Styles

activity_main.xml
--------------------
 <TextView
        
        style="@style/CodeFont"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"             
        android:layout_marginTop="40dp"
        android:text="@string/Pop_Up_Menu" 
        style="@style/CodeFont"/>

string.xml
---------------
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">MyMenu</string>
    <string name="action_settings">Settings</string>
    <string name="action_music">Music</string>
    <string name="action_games">Games</string>
    <string name="hello_world">Hello world!</string>
<string name="Pop_Up_Menu">PopUpMenu</string>
</resources>


style.xml
------------
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">serif</item>
    </style>


Thursday, November 28, 2013

Back button pressed

created four activity, i want to go last activity to second activity through back button pressed.
---------------------------------------------------------------------------------------------
Main_activity.java
Second.java
Third.java
Last.java
------------
public class Last extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.last);

}
@SuppressLint("InlinedApi")
@Override
public void onBackPressed()
{
    super.onBackPressed(); 
    Intent intent = new Intent(getApplicationContext(), Second.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

}
}

Friday, October 18, 2013

How to convert Bitmap to String and String to Bitmap


Bitmap to String:
---------------------public String BitMapToString(Bitmap bitmap){
            ByteArrayOutputStream baos=new  ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
            byte [] arr=baos.toByteArray();
            String result=Base64.encodeToString(arr, Base64.DEFAULT);
            return result;
      }


String to Bitmap:
----------------------public Bitmap StringToBitMap(String image){
       try{
           byte [] encodeByte=Base64.decode(image,Base64.DEFAULT);
           Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
           return bitmap;
         }catch(Exception e){
           e.getMessage();
          return null;
         }
 }

Parse the below url by using JSON. Display the profile picture and the name


URL:  
http://cancos.quadlogix.com/auth/friends 

MainActivity.java
---------------------
package com.kundan.jsonparsingex;


import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
public static final String URL="http://cancos.quadlogix.com/auth/friends";
Button btn,btn2;
static ListView lv;
static TextView tv1;
static ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) findViewById(R.id.listView1);
tv1=(TextView) findViewById(R.id.textView1);
iv=(ImageView) findViewById(R.id.imageView1);
btn=(Button) findViewById(R.id.button1);
btn2=(Button) findViewById(R.id.button2);
btn2.setEnabled(false);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
GetJSONData task = new GetJSONData();
       task.execute(new String[] { URL });
       Toast.makeText(getApplicationContext(), "please wait till image and text loaded...", Toast.LENGTH_LONG).show();
       btn2.setEnabled(true);
}
});


      btn2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
lv.setAdapter(new MyImageAdapter(getApplicationContext(), GetJSONData.mIcon,GetJSONData.nameID));

}
});

}



}

GetJSONData.java
---------------------------

package com.kundan.jsonparsingex;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Base64;
import android.util.Log;

public class GetJSONData extends AsyncTask<String, Void, String> {
static String[] nameID=null;
static Bitmap[] mIcon=null;
static String[] imageID=null;
@Override
protected String doInBackground(String... urls) {
String output = null;
       for (String url : urls) {
         
output = getOutputFromUrl(url);
       }
             
       return output;
}

private String getOutputFromUrl(String url) {
String output = null;
try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            output = EntityUtils.toString(httpEntity);
            System.out.println(output);
           try {
JSONObject jobj=new JSONObject(output);
JSONArray jarray=jobj.getJSONArray("data");
System.out.println("////////"+jarray);
JSONObject jobject=null;
nameID=new String[jarray.length()];
imageID=new String[jarray.length()];
mIcon = new Bitmap[jarray.length()];
for(int i=0;i<jarray.length();i++){
jobject=jarray.getJSONObject(i);
nameID[i]=jobject.getString("name");
imageID[i]=jobject.getString("profile_image");
mIcon[i] = StringToBitMap(imageID[i]);
//System.out.println("++++++++++"+nameID[i]);
//System.out.println("++++++++++"+imageID[i]);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}    
         
            
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
return output;
}
@Override
   protected void onPostExecute(String output) {
super.onPostExecute(output);
MainActivity.tv1.setText(nameID[0]);
MainActivity.iv.setImageBitmap(mIcon[0]); 
   
   }

public Bitmap StringToBitMap(String encodedString) {
   try {
       byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
       Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,encodeByte.length);
       return bitmap;
   } catch (Exception e) {
       e.getMessage();
       return null;
   }
}
 
}

MyImageAdapter.java
---------------------------
package com.kundan.jsonparsingex;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyImageAdapter extends BaseAdapter  {
Context context;
String[] nameID;
Bitmap[] imgId;
static String str1;
public MyImageAdapter(Context context,Bitmap[] ImageID, String[] nameID ) {
this.context=context;
this.imgId=ImageID;
this.nameID=nameID;
}

@Override
public int getCount() {
return nameID.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView=inflater.inflate(R.layout.image_view, parent,false);
TextView name=(TextView) rowView.findViewById(R.id.nameView);
ImageView image=(ImageView) rowView.findViewById(R.id.imageView1);
name.setText(nameID[position]);
image.setImageBitmap(imgId[position]);
return rowView;
}

}

activity_main.xml
--------------------
<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"
   
    tools:context=".MainActivity" >

   <ListView
        android:id="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:divider="#990000"
        android:dividerHeight="1dip"
        android:paddingTop="5dip"
        android:layout_marginTop="150dp">
    </ListView>

   <Button
       android:id="@+id/button1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="Load Profile" />

   <ImageView
       android:id="@+id/imageView1"
       android:layout_width="50dp"
       android:layout_height="50dp"
       android:layout_alignParentLeft="true"
       android:layout_below="@+id/button1"
       android:src="@drawable/ic_launcher" />

   <Button
       android:id="@+id/button2"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_below="@+id/imageView1"
       android:layout_marginTop="16dp"
       android:text="View all Profile" />

   <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignBottom="@+id/imageView1"
       android:layout_marginLeft="19dp"
       android:layout_toRightOf="@+id/imageView1"
       android:text="TextView" />

</RelativeLayout>


image_view.xml
---------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/nameView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/imageView1"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000099" />

</RelativeLayout>


Monday, October 14, 2013

ActionBar Tabs using FragmentPagerAdapter

MainActivity .java
------------------------

package com.kundan.actionbar_tabs;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;

@SuppressLint("NewApi")
public class MainActivity extends FragmentActivity implements TabListener {
private String[] tabs = { "One", "Two" };
private ViewPager viewPager;
   
   private ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        viewPager.setAdapter(new TabsPagerAdapter(getSupportFragmentManager()));
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        

        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
        }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());


}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

}

TabsPagerAdapter .java
-----------------------------
package com.kundan.actionbar_tabs;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPagerAdapter extends FragmentPagerAdapter{

public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int index) {
switch (index) {
       case 0:
           
           return new One();
       case 1:
          
           return new Two();
       
       }
 
       return null;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return 2;
}

}
One .java
------------

package com.kundan.actionbar_tabs;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class One extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup viewGroup=(ViewGroup) inflater.inflate(R.layout.first, container,false);
return viewGroup;
 
}

}

Two .java
----------------
package com.kundan.actionbar_tabs;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Two extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup viewGroup=(ViewGroup) inflater.inflate(R.layout.two, container,false);
return viewGroup;
 
}

}


activity_main.xml
-------------------
<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"
    tools:context=".MainActivity" >
<android.support.v4.view.ViewPager 
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

first.xml
--------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#996699">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First fragment" 
        android:layout_gravity="center"/>

</LinearLayout>

two.xml
-------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#996600">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second Fragment" 
        android:layout_gravity="center"
        />

</LinearLayout>




NOTE: you can slide left or right also...!!!

Friday, October 11, 2013

XML Parsing using XmlPullParser

players.xml
------------
<?xml version="1.0" encoding="UTF-8"?>
<players>
    <player>
        <id>1</id>
        <name>SACHIN</name>
        <salary>50000</salary>      
    </player>
    <player>
        <id>2</id>
        <name>KUNDAN</name>
        <salary>60000</salary>  
    </player>
    
</players>

player.java
-------------
package com.example.xmlpullparsing;
public class Player {
private int id;
private String name;
private float salary;

    
    public int getId() {
return id;
}


public void setId(int id) {
this.id = id;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public float getSalary() {
return salary;
}


public void setSalary(float salary) {
this.salary = salary;
}


@Override
    public String toString() {
        return " Id= "+id + "\n Name= " + name + "\n Salary= " + salary;
    }
}

XmlPullParserHandler .java
--------------------------------

package com.example.xmlpullparsing;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;


public class XmlPullParserHandler {
    private List<Player> players= new ArrayList<Player>();
    private Player player;
    private String text;

    public List<Player> getPlayers() {
        return players;
    }

    public List<Player> parse(InputStream is) {
           try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(true);
            XmlPullParser  parser = factory.newPullParser();

            parser.setInput(is, null);

            int eventType = parser.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                String tagname = parser.getName();
                switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (tagname.equalsIgnoreCase("player")) {
                        // create a new instance of employee
                        player = new Player();
                    }
                    break;

                case XmlPullParser.TEXT:
                    text = parser.getText();
                    break;

                case XmlPullParser.END_TAG:
                    if (tagname.equalsIgnoreCase("player")) {
                        // add employee object to list
                        players.add(player);
                    }else if (tagname.equalsIgnoreCase("id")) {
                    player.setId(Integer.parseInt(text));
                    }  else if (tagname.equalsIgnoreCase("name")) {
                    player.setName(text);
                    } else if (tagname.equalsIgnoreCase("salary")) {
                    player.setSalary(Float.parseFloat(text));
                    } 
                    break;

                default:
                    break;
                }
                eventType = parser.next();
            }

        } catch (XmlPullParserException e) {
        e.printStackTrace();
       
        catch (IOException e) {
        e.printStackTrace();
        }

        return players;
    }
}

MainActivity .java
-------------------
package com.example.xmlpullparsing;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
       ListView listView = (ListView) findViewById(R.id.listView1);
       
        List<Player> players = null;
        try {
            XmlPullParserHandler parser = new XmlPullParserHandler();
            InputStream is=getAssets().open("players.xml");
            players = parser.parse(is);
            
            ArrayAdapter<Player> adapter =new ArrayAdapter<Player>(this,android.R.layout.simple_list_item_1, players);
            listView.setAdapter(adapter);
            
        } catch (IOException e) {e.printStackTrace();}
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
}

activity_main.xml
-------------------
<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"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:divider="#FFCC00"
    android:dividerHeight="4px"
   
    >

    </ListView>

</RelativeLayout>