Aug 30, 2013

Send list of file between activities

To send list of file via intent, in sender activity:

   ArrayList<File> fileList = new ArrayList<File>();
   ...

   Intent intent = new Intent(MainActivity.this, secondActivity.class);
   intent.putExtra("FILES_TO_SEND", fileList);
   startActivity(intent);


In receiver activity:

  ArrayList<File> filelist = 
      (ArrayList<File>)getIntent().getSerializableExtra("FILES_TO_SEND");


Aug 29, 2013

Simple example of Navigation Drawer

Navigation drawer is a panel that transitions in from the left edge of the screen and displays the app’s main navigation options.

It is a simple example of Navigation Drawer:
Simple example of Navigation Drawer
Simple example of Navigation Drawer


Modify layout to add <android.support.v4.widget.DrawerLayout > as root.
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <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" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="android-coding.blogspot.com" />
    </RelativeLayout>

    <ListView
        android:id="@+id/drawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/background_dark"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>


Create /res/layout/drawer_list_item.xml to define row layout of the ListView in our drawer.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textColor="@android:color/white"
    android:textSize="24sp"/>


MainActivity.java
package com.example.androidnavigationdrawer;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
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 MainActivity extends Activity {
 
 private String[] optsArray = {
   "Option 1",
   "Option 2",
   "Option 3",
   "Option 4"
 };
    private DrawerLayout drawer;
    private ListView drawerList;
    ArrayAdapter<String> optionArrayAdapter;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.drawer);
        
        optionArrayAdapter = new ArrayAdapter<String>(this, 
          R.layout.drawer_list_item, 
          optsArray);
        drawerList.setAdapter(optionArrayAdapter);
        
        drawerList.setOnItemClickListener(new OnItemClickListener(){

   @Override
   public void onItemClick(AdapterView<?> parent, View view, 
     int position, long id) {
    Toast.makeText(MainActivity.this, 
      optsArray[position], 
      Toast.LENGTH_LONG).show();
   }});
 }

 @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;
 }

}

/res/menu/main.xml, it's the auto generated menu resources by Eclipse. You can ignore it by removing onCreateOptionsMenu() in MainActivity.java if you don't need it.
<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>


more: DrawerLayout with custom Layout/View

Aug 28, 2013

Error retrieving parent for item: No resource found that matches the given name...

If you import the API Demo in Android SDK, you will have the error of "Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.NoActionBar'."

Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.NoActionBar'.
To solve it, you have to fix your Target API Level. Right click the Project, select Properties. Select Android tab, and select higher API level.


Then Clean and Build your project again.

Aug 21, 2013

Game On! - Intro to Open GL ES 3.0

Game On! - Intro to Open GL ES 3.0
The video provide you with a breakdown of what's new in OpenGL ES 3.0!

Aug 19, 2013

Google Wallet Integration with Instant Buy

Google Wallet Integration with Instant Buy

During this session one of partners, Tagstand, will talk about their Google Wallet Instant Buy API integration experience. We will show a demo of the app followed by a detailed discussion on what it took them to build this app and integrate with Instant Buy API. Developers selling physical goods and services on Android should use this URL to get access to Instant Buy API - http://getinstantbuy.withgoogle.com

Cloud save using Play Games services


Game On!: Cloud Save
Join Todd and Bruno from the Play Games team as they share exciting news and updates, and go over some of the finer points of enabling cloud save using Play Games services.

Aug 15, 2013

Implement horizontal and scrollable Radio Button Group

This example implement RadioButton Group horizontally and scrollable.

horizontal and scrollable Radio Button Group
horizontal and scrollable Radio Button Group


<LinearLayout 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: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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android-coding.blogspot.com" />

    <RadioGroup
        android:id="@+id/radiogroup_vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/normalradiobutton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="normal option 1" />

        <RadioButton
            android:id="@+id/normalradiobutton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="normal option 2" />
    </RadioGroup>
    
    <RadioGroup
        android:id="@+id/radiogroup2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radiobutton1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="option 1" />

        <RadioButton
            android:id="@+id/radiobutton2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="option 2" />
    </RadioGroup>

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioGroup
            android:id="@+id/radiogroup3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/radiobuttona"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="option A" />

            <RadioButton
                android:id="@+id/radiobuttonb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="option B" />

            <RadioButton
                android:id="@+id/radiobuttonc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="option C" />
            <RadioButton
                android:id="@+id/radiobuttond"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="option D" />

            <RadioButton
                android:id="@+id/radiobuttone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="option E" />
        </RadioGroup>
    </HorizontalScrollView>

</LinearLayout>


In the example, <RadioGroup> with id=radiogroup_vertical is default vertical RadioGroup. <RadioGroup> with id=radiogroup2 is horizontal RadioGroup with android:orientation="horizontal". <RadioGroup> with id=radiogroup3 is another horizontal RadioGroup, but with 5 option expect more space than device's screen width. So place it in a <HorizontalScrollView> to make it svrollable.

Infolinks In Text Ads