Open top menu

                                  Android-Splash Screen

try this code...


SplashActivity.java
...................................................................................................................................................................

package com.example.androidbeginnerpoint;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {

public void run() {
Intent intent = new Intent(SplashScreen.this,MainActivity.class);                  
startActivity(intent);
       finish();
overridePendingTransition(R.anim.slide_in_right,R.anim.stay);

}
}, 3000);


}
}

Read more


      How to Hide Actionbar in Android



In this Tutorial we will explain how to hide ActionBar Programmatically  or via Manifest.xml.

   

Step 1. first , Manifest.xml class...
 mostally dosen't required actionbar in Splash screen.

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
...................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidbeginnerpoint"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashScreen"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.webnetware.singingbowl.MainActivity"
            android:screenOrientation="portrait" >
        </activity>
     
    </application>

</manifest>

Step 2. second ,SplashActivity.java programmtic....

 ActionBar actionBar = getActionBar(); /*or getSupportActionBar();*/
                  // Hide actionbar
 actionBar.hide();
..................................................................................................................................................................


package com.example.androidbeginnerpoint;


import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActionBar actionBar = getActionBar(); /*or getSupportActionBar();*/
                  // Hide actionbar
actionBar.hide();
                // show actionbar
               //  actionBar.Show();
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {

public void run() {
Intent intent = new Intent(SplashScreen.this,MainActivity.class);                                        
startActivity(intent);
   finish();
overridePendingTransition(R.anim.slide_in_right,R.anim.stay);

}
}, 3000);


}
}


Read more


                   

             Android-Implement Image Gallery Wigets 

...................................................................................................................................................................

Stepe 1. create activity_main.xml res folder...

activity_main.xml
...................................................................................................................................................................

<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" >     
    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logoweb" />
    <ImageView
        android:id="@+id/image1"
        android:layout_width="215dp"
        android:layout_height="270dp"
        android:layout_gravity="center_horizontal"
        android:background="#cfcfcf"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:src="@drawable/logoweb" />
</LinearLayout>


Stepe 2. create atter.xml inside res/values/ folder...
...................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<resources>
    
<declare-styleable name="MyGallery">
    
<attr name="android:galleryItemBackground" />

</declare-styleable>

</resources>



Stepe 3. create MainActivity.java inside src folder...
...................................................................................................................................................................
package com.androidbeginner.testcode;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
@SuppressWarnings("deprecation")
public class MainActivity extends Activity {
 
Integer[] imageIDs = {
R.drawable.k,
R.drawable.l,
R.drawable.p,
R.drawable.t  
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle("Image Gallery example");
setContentView(R.layout.activity_main);
 
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position,long id)
{
Toast.makeText(getBaseContext(),"photo" + (position + 1) + " onClick",Toast.LENGTH_SHORT).show();  
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Context contx)
{
context = contx;
 
TypedArray styl =obtainStyledAttributes(R.styleable.MyGallery);
itemBackground = styl.getResourceId(R.styleable.MyGallery_android_galleryItemBackground, 0);
styl.recycle();
}
 
public int getCount() {
return imageIDs.length;
}
 
public Object getItem(int position) {
return position;
}
 
public long getItemId(int position) {
return position;
}
 
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}

try this code....

view More 

Read more


             Android- Display gallery using ViewPager 

...................................................................................................................................................................

In this Tutorila we will explain how to display gallery using viewpager in android.
try this code......


Stepe 1. create activity_main.xml inside res folder...
...................................................................................................................................................................

<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"
    tools:context="com.androidbeginner.testcode.MainActivity" >

   
   
    <android.support.v4.view.ViewPager
        android:id="@+id/myviewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="2dp"/>      
   
</LinearLayout>


Stepe 2. create MainActivity.java inside src folder...
...................................................................................................................................................................

package com.androidbeginner.testcode;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class MainActivity extends Activity {


ViewPager viewPager;
    int[] imageArray;
    Bundle bundle;
    final TypedArray imageArrayIcon=null;
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);    
        viewPager = (ViewPager) findViewById(R.id.myviewpager);
   ImagePagerAdapter adapter = new ImagePagerAdapter();
   viewPager.setAdapter(adapter);


}
public class ImagePagerAdapter extends PagerAdapter {

   

   private int[] mImages = new int[]{R.drawable.logoweb,R.drawable.k,R.drawable.l,R.drawable.p,R.drawable.t};
   @Override

   public int getCount() {

       return mImages.length;

   }

   @Override

   public boolean isViewFromObject(View view, Object object) {

       return view == ((ImageView) object);

   }
   @Override

   public Object instantiateItem(ViewGroup container, int position) {

       Context context = MainActivity.this;
       ImageView imageView = new ImageView(context);      
       imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
       imageView.setImageResource(mImages[position]);      
       ((ViewPager) container).addView(imageView, 0);

       return imageView;
   }
 
   @Override

   public void destroyItem(ViewGroup container, int position, Object object) {

       ((ViewPager) container).removeView((ImageView) object);

   }

}
}




thank you for watching...

Read more

                                         
how to remove duplicates string from Arraylist in android ..try this code



ArrayList<String> list = new ArrayList<String>() 
HashSet<String> pure = new LinkedHashSet<String>();
   
HashSet<String> dup = new LinkedHashSet<String>();
  
 boolean b = false;
 
  list.add("kaushik");
 
   list.add("kaushik");
 
   list.add("how");
 
  list.add("you");
  
 list.add("find");
 
  list.add("find");

 
  for(Iterator iterator= list.iterator();iterator.hasNext();)
  
 {
       
String value = (String)iterator.next();
      
 System.out.println(value);

     
 if(b==pure .add(value))
         
dup.add(value);
     
else
         
  pure .add(value);        


   }
 
  System.out.println(pure );
 
  System.out.println(dup);
Read more


In this tutorial we will implement  ViewPager with ImageView in android.

try this code

stepe 1.create ViewPagerAdapter.java  class in src folder..
...................................................................................................................................................................


package com.androidbeginner.testcode;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ViewPagerAdapter extends PagerAdapter {

Context context;
String[] number;
String[] name;
String[] weight;
int[] ball;
LayoutInflater inflater;

public ViewPagerAdapter(Context context, String[] number, String[] name,
String[] weight, int[] ball) {
this.context = context;
this.number = number;
this.name = name;
this.weight = weight;
this.ball = ball;
}

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

@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

// Declare Variables
TextView nubmer1;
TextView name1;
TextView weight1;
ImageView img1;

inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container,
false);


nubmer1 = (TextView) itemView.findViewById(R.id.number1);
name1 = (TextView) itemView.findViewById(R.id.ball);
weight1 = (TextView) itemView.findViewById(R.id.weight1);

// Capture position and set to the TextViews
nubmer1.setText(number[position]);
name1.setText(name[position]);
weight1.setText(weight[position]);

// Locate the ImageView in viewpager_item.xml
img1 = (ImageView) itemView.findViewById(R.id.flag);
// Capture position and set to the ImageView
img1.setImageResource(ball[position]);

// Add viewpager_item.xml to ViewPager
((ViewPager) container).addView(itemView);

return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// Remove viewpager_item.xml from ViewPager
((ViewPager) container).removeView((RelativeLayout) object);

}
}

stepe2. create viewpager_item.xml inside res folder....
...................................................................................................................................................................


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:padding="10dp" >

    <TextView
        android:id="@+id/number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Number:-" />

    <TextView
        android:id="@+id/number1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/number" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/number"
        android:text="Name:-" />

    <TextView
        android:id="@+id/ball"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/number1"
        android:layout_toRightOf="@+id/name" />

    <TextView
        android:id="@+id/weight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/name"
        android:text="Weight:-" />

    <TextView
        android:id="@+id/weight1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ball"
        android:layout_toRightOf="@+id/weight" />

    <ImageView
        android:id="@+id/flag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="#000000"
        android:padding="1dp" />

</RelativeLayout>

stepe 3. create MainActivity.java inside src folder..
...................................................................................................................................................................
package com.androidbeginner.testcode;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

public class MainActivity extends Activity {


ViewPager viewPager;
PagerAdapter adapter;
String[] number;
String[] name;
String[] weight;
int[] ballimg;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);


number = new String[] { "1", "2", "3", "4", "5" };

name = new String[] { "football", "football", "football","football" };

weight = new String[] { "70gm", "150gm","315gm", "90gm", "193gm"};


ballimg = new int[] { R.drawable.a, R.drawable.b,
R.drawable.c, R.drawable.d,
R.drawable.e };


viewPager = (ViewPager) findViewById(R.id.myviewpager);

adapter = new ViewPagerAdapter(MainActivity.this, number, name, weight, ballimg);

viewPager.setAdapter(adapter);

}
}




stepe4. create activity_main.xml inside res folder..
...................................................................................................................................................................

<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"
    tools:context="com.androidbeginner.testcode.MainActivity" >  
 
    <android.support.v4.view.ViewPager
        android:id="@+id/myviewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="2dp"/>    
 
</LinearLayout>












Read more