Friday 28 February 2014

Notes Android application

Tuesday 25 February 2014

Displaying Context menu for one click in ListView



activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ff0000">

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#ff0000"
        android:divider="#ffffff"
        android:dividerHeight="1dp">
    </ListView>

</LinearLayout>

MainActivity.java:
package com.ram.listviewwithcustommenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener {
    String[] ITEMS = { "item1", "item2", "item3", "item4", "item5", "item6",
            "item7", "item8", "item9", "item10" };

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

        ListView listView = (ListView) findViewById(R.id.listView1);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_1, ITEMS);

        listView.setAdapter(adapter);

        registerForContextMenu(listView);

        listView.setOnItemClickListener(this);
    }

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

    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
        // TODO Auto-generated method stub
        this.openContextMenu(v);
    }
}

RamsAndroidBlog Android application

Hi friends here you can download this blog as android application so that anything i'm updating in the blog you can get that update in your mobile through this application.
download from following link:
https://play.google.com/store/apps/details?id=com.ram.ramsandroidblog





Flash Light Android Application

Friday 14 February 2014

Fragment Transactions Example in Android





activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button_addfraga"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="add FragA" />

        <Button
            android:id="@+id/button_replacefragb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Replace FragB" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button_replacefragc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Replace FragC" />

        <Button
            android:id="@+id/button_removefragc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remove Fragc" />
    </TableRow>

    <FrameLayout
        android:id="@+id/fragArea"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

</LinearLayout>

fraga.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="#ccffcc">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is FragmentA"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

fragb.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="#ccffff">
   
 <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is FragmentB"
        android:textAppearance="?android:attr/textAppearanceLarge" />
   
</LinearLayout>

fragc.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="#ffffcc">
   
 <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is Fragmentc"
        android:textAppearance="?android:attr/textAppearanceLarge" />
   
</LinearLayout>

FragA.java:
package com.ram.fragmenttransactions;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@SuppressLint("NewApi")
public class FragA extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.fraga, container, false);
    }
}

FragB.java:
package com.ram.fragmenttransactions;

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

public class Fragb extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.fragb, container, false);
    }
}

FragC.java:
package com.ram.fragmenttransactions;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@SuppressLint("NewApi")
public class FragC extends Fragment{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.fragc, container, false);
    }
}

MainActivity.java:
package com.ram.fragmenttransactions;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

@SuppressLint("NewApi")
public class MainActivity extends Activity implements OnClickListener {
    Button b1, b2, b3, b4;
    FragmentManager fm;

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

        fm = getFragmentManager();

        b1 = (Button) findViewById(R.id.button_addfraga);
        b2 = (Button) findViewById(R.id.button_replacefragb);
        b3 = (Button) findViewById(R.id.button_replacefragc);
        b4 = (Button) findViewById(R.id.button_removefragc);

        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        b3.setOnClickListener(this);
        b4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.button_addfraga:

            FragmentTransaction ft1 = fm.beginTransaction();
            ft1.add(R.id.fragArea, new FragA());
            ft1.commit();

            break;

        case R.id.button_replacefragb:

            FragmentTransaction ft2 = fm.beginTransaction();

            ft2.replace(R.id.fragArea, new Fragb());
            ft2.addToBackStack(null);
            ft2.commit();

            break;
        case R.id.button_replacefragc:
            FragmentTransaction ft3 = fm.beginTransaction();

            ft3.replace(R.id.fragArea, new FragC(), "fragc");
            ft3.addToBackStack(null);
            ft3.commit();
            break;
        case R.id.button_removefragc:
            FragmentTransaction ft4 = fm.beginTransaction();

            FragC fc = (FragC) fm.findFragmentByTag("fragc");

            ft4.remove(fc);
            ft4.commit();
            break;
        }
    }

}

RamsAndroid Blog Andoid Application

Hi friends good news for you,
Here you will get my blog as a android application in your mobile you can download from below link

https://play.google.com/store/apps/details?id=com.ram.ramsandroidblog

Monday 10 February 2014

Android Basics Tutorial Application

Hi to all,
I have uploaded application in Google Play Store on Android application development .It will useful to who are learning android and in this application you can find video tutorials also .
you can download from here : https://play.google.com/store/apps/details?id=com.ram.androidbasicstutorial