Tuesday, 27 January 2015

android full application source code



MENU code in android
Res>>Menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.anlistview22.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/
           android:>
    <item android:id="@+id/item1"
        android:title="HOME"></item>
   

</menu>

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

    <string name="app_name">Anlistview22</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
<string name="item1">HOME</string>
   
</resources>







Slidemenu.java
package com.example.slide_menu;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;


import com.navdrawer.SimpleSideDrawer;

public class MainActivity extends Activity {
      SimpleSideDrawer slide_me;
      Button left_button, right_button,new_btn;
      TextView tv1;

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            slide_me = new SimpleSideDrawer(this);
            slide_me.setLeftBehindContentView(R.layout.left_menu);
            slide_me.setRightBehindContentView(R.layout.right_menu);
            tv1=(TextView)findViewById(R.id.tv1);
            new_btn=(Button)findViewById(R.id.button1);
           
            left_button = (Button) findViewById(R.id.left_buton);
            right_button = (Button) findViewById(R.id.right_buton);
           
            new_btn.setOnClickListener(new View.OnClickListener() {
                 
                  @Override
                  public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        tv1.setText("Clicked");
                        slide_me.toggleLeftDrawer();
                  }
            });
            left_button.setOnClickListener(new View.OnClickListener() {
                  private ListView l1;
                  @Override
                  public void onClick(View v) {
                       
                        // TODO Auto-generated method stub
                        slide_me.toggleLeftDrawer();
                         l1=(ListView)findViewById(R.id.listView1);
                         l1.setAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.dataelements)));
                        

                  }
            });
            right_button.setOnClickListener(new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub
                        slide_me.toggleRightDrawer();
                  }
            });
      }
}

Leftbutton.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:background="#ffff"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Left Menu"
        android:textColor="#ffffff" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="new_widow"
        android:onClick="action" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>
Values>>String.xml

<resources>

    <string name="app_name">slide_menu</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">Slide Demo</string>
   
    <string-array name="dataelements">
        <item>one</item>
        <item>two</item>
        <item>three</item>
        <item>four</item>
        <item>five</item>
      
       
       
       
       
    </string-array>

</resources>



No comments:

Post a Comment