Thursday, October 12, 2017

Technical Links

Check Internet is connected or not?


https://github.com/novoda/merlin/blob/master/core/src/main/java/com/novoda/merlin/Endpoint.java


Searchview with popup and custom list.
https://github.com/jessieeeee/SearchView

http://www.sanfoundry.com/java-programming-examples-data-structures/

Tuesday, June 6, 2017

Ielts


Podcast for Ielts:
http://www.ieltspodcast.com


CNN Podcast
http://podcast.cnn.com/

Boss-files:
http://podcast.cnn.com/boss-files/episode/all/19xt0Fkedyebiz/qb8uyb.1-1.html

https://www.ted.com/talks


https://www.englishclub.com/vocabulary/phrasal-verbs-list.htm
https://www.englishclub.com

http://www.worldclasslearning.com/english/five-verb-forms.html

Monday, November 7, 2016

Date formate like whatspp listing datetime

1. You need to set a date formate.
 
SimpleDateFormat simpleDateFormat =
        new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
 
 
2. Get Current Date.
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
String formattedDate = df.format(c.getTime());
System.out.println("====currentDateTimeString=" + formattedDate);

3. Prepare to compare with twodate.





try {
    Date date1 = simpleDateFormat.parse("8-11-2016 10:30:10");
    Date today = simpleDateFormat.parse("8-11-2016 10:30:10");
    Date date_yeasterday = simpleDateFormat.parse("7-11-2016 10:30:10");
    Date date_between_seven = simpleDateFormat.parse("5-11-2016 10:30:10");
    Date date_after_seven = simpleDateFormat.parse("31-10-2016 10:30:10");

    printDifference(date1, today, "8-11-2016 10:30:10");
    printDifference(date1, date_yeasterday, "7-11-2016 10:30:10");
    printDifference(date1, date_between_seven, "5-11-2016 10:30:10");
    printDifference(date1, date_after_seven, "31-10-2016 10:30:10");

} catch (ParseException e) {
    e.printStackTrace();
}
 
 
4. Call Method only and you will get results like that:

Today: 10:12 pm
1 day ago: Yeasterday
Week Day: mon,tue,sat,sun
Before 7 day : date formate what event you want.

 
 
  public void printDifference(Date startDate, Date endDate, String finalDate) {

       //milliseconds        long different = endDate.getTime() - startDate.getTime();

       System.out.println("startDate : " + startDate);       System.out.println("endDate : " + endDate);       System.out.println("different : " + different);
        long secondsInMilli = 1000;
        long minutesInMilli = secondsInMilli * 60;
        long hoursInMilli = minutesInMilli * 60;
        long daysInMilli = hoursInMilli * 24;

        long elapsedDays = different / daysInMilli;
        different = different % daysInMilli;

        long elapsedHours = different / hoursInMilli;
        different = different % hoursInMilli;

        long elapsedMinutes = different / minutesInMilli;
        different = different % minutesInMilli;

        long elapsedSeconds = different / secondsInMilli;

        System.out.printf(              "%d days, %d hours, %d minutes, %d seconds%n",               elapsedDays,               elapsedHours, elapsedMinutes, elapsedSeconds);
        if (elapsedDays == 0) {
            System.out.printf(
                    "%d days",
                    elapsedDays);

            System.out.println("elapsedDays if same date" + formatTimeOnly(MainActivity.this, finalDate));

        } else if (elapsedDays == (-1)) {
            System.out.printf(
                    "%d days",
                    elapsedDays);

            System.out.println("elapsedDays if before day Yesterday" + elapsedDays);
        } else if (elapsedDays == (-2) || elapsedDays == (-3) || elapsedDays == (-4) || elapsedDays == (-5) || elapsedDays == (-6) || elapsedDays == (-7)) {
            System.out.printf(
                    "%d days",
                    elapsedDays);
            SimpleDateFormat sdf = new SimpleDateFormat("EEE");
//            Date d = new Date();            String dayOfTheWeek = sdf.format(endDate);
            System.out.println("elapsedDays if week day=====" + dayOfTheWeek);

        } else {
            System.out.printf(
                    "%d days",
                    elapsedDays);
            System.out.println("elapsedDays if greater then week day" + formatDateOnly(MainActivity.this, finalDate));
        }

    }


    public static String formatTimeOnly(Context context, String timeToFormat) {
        String finalDateTime = "";
        SimpleDateFormat iso8601Format = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");

        Date date = null;
        if (timeToFormat != null) {
            try {
                date = iso8601Format.parse(timeToFormat);
            } catch (ParseException e) {
                date = null;
            }

            if (date != null) {
                long when = date.getTime();
                int flags = 0;
                flags |= android.text.format.DateUtils.FORMAT_SHOW_TIME;
                finalDateTime = android.text.format.DateUtils.formatDateTime(context,
                        when + TimeZone.getDefault().getOffset(when), flags);


            }
        }

        return finalDateTime;
    }


    public static String formatDateOnly(Context context, String timeToFormat) {


        String finalDateTime = "";

        SimpleDateFormat iso8601Format = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");

        Date date = null;
        if (timeToFormat != null) {
            try {
                date = iso8601Format.parse(timeToFormat);
            } catch (ParseException e) {
                date = null;
            }

            if (date != null) {
                long when = date.getTime();
                int flags = 0;
                flags |= android.text.format.DateUtils.FORMAT_SHOW_DATE;
                flags |= android.text.format.DateUtils.FORMAT_SHOW_YEAR;

                finalDateTime = android.text.format.DateUtils.formatDateTime(context,
                        when + TimeZone.getDefault().getOffset(when), flags);

            }
        }

        return finalDateTime;
    }
 

Tuesday, August 18, 2015

Arraylist In SharedPreference Android Example

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SharedPreference {
    public static final String PREFS_NAME = "Valkesh_android";
    public static final String FAVORITES = "Developer_favorites";
    public SharedPreference() {
        super();
    }
public void storeFavorites(Context context, List favorites) {
// used for store arrayList in json format
        SharedPreferences settings;
        Editor editor;
        settings = context.getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE);
        editor = settings.edit();
        Gson gson = new Gson();
        String jsonFavorites = gson.toJson(favorites);
        editor.putString(FAVORITES, jsonFavorites);
        editor.commit();
    }
    public ArrayList loadFavorites(Context context) {
// used for retrieving arraylist from json formatted string
        SharedPreferences settings;
        List favorites;
        settings = context.getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE);
        if (settings.contains(FAVORITES)) {
            String jsonFavorites = settings.getString(FAVORITES, null);
            Gson gson = new Gson();
            BeanSampleList[] favoriteItems = gson.fromJson(jsonFavorites,BeanSampleList[].class);
            favorites = Arrays.asList(favoriteItems);
            favorites = new ArrayList(favorites);
        } else
            return null;
        return (ArrayList) favorites;
    }
    public void addFavorite(Context context, BeanSampleList beanSampleList) {
        List favorites = loadFavorites(context);
        if (favorites == null)
            favorites = new ArrayList();
        favorites.add(beanSampleList);
        storeFavorites(context, favorites);
    }
    public void removeFavorite(Context context, BeanSampleList beanSampleList) {
        ArrayList favorites = loadFavorites(context);
        if (favorites != null) {
            favorites.remove(beanSampleList);
            storeFavorites(context, favorites);
        }
    }
}

Monday, February 16, 2015

Setup ADB Udev Rule

 Setup ADB Udev Rules

  • Set the device to use USB Debug
  • declare a corresponding Udev rule on your Ubuntu box
After setting the device in USB Debug mode and connecting it to a USB port, throw the command :
Check your Device Vender_id And Product_id.

Step no 1:
Open terminal: lsusb -> check your device v_id & p_id

Step no 2:  sudo gedit /etc/udev/rules.d/99-android.rules

 Insert this code

 # Google Nexus 7 16 Gb
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666", OWNER="your-login"    # MTP mode with USB debug on


SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0c03", MODE="0666", OWNER="your-login"    # MTP mode with USB debug on


Step no 3: save file

Step 4: on terminal:  sudo service udev restart



Please contact more details : bernaerts.dyndns.org/linux/74-ubuntu/245-ubuntu-precise-install-android-sdk

Friday, February 13, 2015

Introduction material-design

Introduction material-design


Please More Details....
http://www.google.com/design/spec/material-design/introduction.html



Saturday, October 4, 2014

Share on Facebook, gmail, twitter via Intent in android

Share via Facebook

 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
   shareIntent.setType("text/plain");
   shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
   shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));

   PackageManager pm = v.getContext().getPackageManager();
   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
     for (final ResolveInfo app : activityList) 
     {
         if ((app.activityInfo.name).contains("facebook")) 
         {
           final ActivityInfo activity = app.activityInfo;
           final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
          shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
          shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
          shareIntent.setComponent(name);
          v.getContext().startActivity(shareIntent);
          break;
        }
      }
 
 
 Share via Twitter
 
  Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
   shareIntent.setType("text/plain");
   shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
   shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));

   PackageManager pm = v.getContext().getPackageManager();
   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
     for (final ResolveInfo app : activityList) 
      {
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
          {
             final ActivityInfo activity = app.activityInfo;
             final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
             shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
             shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
             shareIntent.setComponent(name);
             v.getContext().startActivity(shareIntent);
            break;
          }
        }
  Share via Gmail
 
 
 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
  shareIntent.setType("text/plain");
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
  shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));

   PackageManager pm = v.getContext().getPackageManager();
   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
       for (final ResolveInfo app : activityList) 
        {
          if ((app.activityInfo.name).contains("gmail")) 
           {
             final ActivityInfo activity = app.activityInfo;
             final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
            shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
             shareIntent.setComponent(name);
             v.getContext().startActivity(shareIntent);
             break;
           }
       } 
Attaching image on Gmail,Facebook,Twitter with Text  
 
 File filePath = context.getFileStreamPath("your.jpg");
 share("gmail",filePath.toString(),"text");
 share("facebook",filePath.toString(),"text");
 share("twitter",filePath.toString(),"text");


void share(String nameApp, String imagePath,String message) 
 { 
 try  
        { 
         List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
 
 Intent share = new Intent(android.content.Intent.ACTION_SEND); 
     share.setType("image/jpeg"); List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0); 
 if (!resInfo.isEmpty()){
  for (ResolveInfo info : resInfo) 
 { Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND); 
 
         targetedShare.setType("image/jpeg");(info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) { 
 
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo"); targetedShare.putExtra(Intent.EXTRA_TEXT,message); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) ); targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); startActivity(chooserIntent);  
} 
 
 } 
 catch(Exception e){ 
 Log.v("VM","Exception while sending image on" + nameApp + " "+ e.getMessage());    
  }
}

Saturday, April 5, 2014

Save & Display image in Gallery in Android

Save & Display image in Gallery

This method can use any where in your save image.
Just call  this image and pass params image name and Bitmap,
Then after,call this method addImageToGallery(file path, mcontex);
  
public static String saveImage(String image_name, Bitmap image_) {
        FileOutputStream image = null;
        // External sdcard location
        File mediaStorageDir = new File(
                Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "Your dir");
        File mediaStorageDir = new File(
                Environment.getExternalStorageDirectory()
                        + "/Pictures/Your dir");

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {   
                mediaStorageDir.mkdir();               
            }
        }
        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
                Locale.getDefault()).format(new Date());
        File mediaFile;
        mediaFile = new File(
                          mediaStorageDir, ""
                      + image_name + timeStamp  + ".png");
        try {        
            image = new FileOutputStream(mediaFile);
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        image_.compress(CompressFormat.PNG, 100, image);
        return mediaFile.getPath();
    }



public static void addImageToGallery(final String filePath, final Context context) {
        ContentValues values = new ContentValues();
        values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(MediaStore.MediaColumns.DATA, filePath);
        context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
    }



Thursday, February 20, 2014

Check Internet and also wifi network is workig in device

Check Internet and also wifi network is workig in device 


Step 1: Create Method


public static boolean isNetworkAvaliable(Context context ) {
        ConnectivityManager connectivityManager = (ConnectivityManager) ctx
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if ((connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null && connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
                || (connectivityManager
                        .getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && connectivityManager
                        .getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                        .getState() == NetworkInfo.State.CONNECTED)) {
            return true;
        } else {
            return false;
        }
    }

Step 2:  Get Value True or false in Bool value

             Boolean isinternetON = Utility.isNetworkAvaliable(context );  

Step 3:  give permission in your AndroidManifest.xml file.
         
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


Sunday, January 12, 2014

Bouncy Scrollview

Bouncy Scrollview Like Facebook Scrollview.


Create one class  BounceScrollView.java in src Folder.
- Basically That is custom view and that is extends to ScrollView 




package com.valkesh.utility;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.ScrollView;

public class BounceScrollView extends ScrollView {
    private View inner;

    private float y;
    private Rect normal = new Rect();

    private boolean isCount = false;

    public BounceScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        if (getChildCount() > 0) {
            inner = getChildAt(0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (inner != null) {
            commOnTouchEvent(ev);
        }

        return super.onTouchEvent(ev);
    }

    public void commOnTouchEvent(MotionEvent e) {
        int action = e.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            break;
        case MotionEvent.ACTION_UP:
            if (isNeedAnimation()) {
                animation();
                isCount = false;
            }
            break;

        case MotionEvent.ACTION_MOVE:
            final float preY = y;
            float nowY = e.getY();
            int deltaY = (int) (preY - nowY);
            if (!isCount) {
                deltaY = 0;
            }

            y = nowY;
            if (isNeedMove()) {
                if (normal.isEmpty()) {
                    normal.set(inner.getLeft(), inner.getTop(),
                            inner.getRight(), inner.getBottom());
                }
                inner.layout(inner.getLeft(), inner.getTop() - deltaY / 2,
                        inner.getRight(), inner.getBottom() - deltaY / 2);
            }
            isCount = true;
            break;

        default:
            break;
        }
    }

    public void animation() {
        TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(),
                normal.top);
        ta.setDuration(200);
        inner.startAnimation(ta);
        inner.layout(normal.left, normal.top, normal.right, normal.bottom);

        normal.setEmpty();

    }

    public boolean isNeedAnimation() {
        return !normal.isEmpty();
    }

    public boolean isNeedMove() {
        int offset = inner.getMeasuredHeight() - getHeight();
        int scrollY = getScrollY();
        if (scrollY == 0 || scrollY == offset) {
            return true;
        }
        return false;
    }

}


Now, open your xml file as your view file.


  <com.valkesh.utility.BounceScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

                 Your view

 </com.valkesh.utility.BounceScrollView>


Wednesday, January 8, 2014

Opacity use with any ColorCode in persontage

Opacity with any ColorCode

Ex: Black color and white color with opacity code.

Below code for black:-
Black color [<color name="black">#000000</color>]
White color [<color name="white">#ffffff</color>]
  
Now if i want to use opacity than you can use below code :-
 
60% opacity with black color
<color name="black">#99000000</color>
 
50% opacity with white color 
<color name="white">#80ffffff</color>

YOU CAN USE ANY COLOR WITH OPACITY CODE.

and below for opacity code:-

Hex Opacity Values
100%  FF
95%  F2
90%  E6
85%  D9
80%  CC
75%  BF
70%  B3
65%  A6
60%  99
55%  8C
50%  80
45%  73
40%  66
35%  59
30%  4D
25%  40
20%  33
15%  26
10%  1A
5%  0D
0%  00

Thursday, August 15, 2013

Base Adapter With Json Data

Step1: You Just Follow Simple Step.

1.Create a new Activity in your Project. (MainActivity.java)


package com.valkesh.baseadapterdemo;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.valkesh.adapter.FriendAdapter;
import com.valkesh.model.FriendDetailsListModel;
import com.valkesh.model.JSONParser;

public class MainActivity extends Activity {
private Context mContext;
private ListView FriendList;
private FriendAdapter friend_Adapter;
private String url = "";
private ArrayList<FriendDetailsListModel> mFriendsList = new ArrayList<FriendDetailsListModel>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FriendList = (ListView) findViewById(R.id.lv_friend_list);
url = "http://valkeshpatel.com/friend/f_id=1";
new ProgressTask().execute();
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}

class ProgressTask extends AsyncTask<String, String, String> {
private ProgressDialog dialog;
private String response = null;

@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(mContext);
dialog.setMessage("Loading Customer...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
}

@Override
protected String doInBackground(String... params) {
JSONParser jParser = new JSONParser();
// get JSON data from URL
response = jParser.getResponseFromUrl(url);
return null;
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// if (dialog.isShowing()) {
dialog.dismiss();
// }

if (response.equalsIgnoreCase("") || response.trim().length() <= 0) {
Toast.makeText(mContext, "No data found", Toast.LENGTH_SHORT)
.show();
} else {
try {
Log.d("Drive_List_response", "" + response);
JSONArray objJsonArry = new JSONArray(response);
for (int i = 0; i < objJsonArry.length(); i++) {
JSONObject objJosn = objJsonArry.getJSONObject(i);
FriendDetailsListModel objModel = new FriendDetailsListModel();
objModel.setF_name(objJosn.getString("name"));
objModel.setDob(objJosn.getString("age"));
objModel.setGender(objJosn.getString("gender"));
mFriendsList.add(objModel);
}
} catch (JSONException e) {
e.printStackTrace();
Log.e("ERROR", e.toString());
}
Log.e("LISTSIZE", "" + mFriendsList.size());
friend_Adapter = new FriendAdapter(mContext, mFriendsList);
FriendList.setAdapter(friend_Adapter);
}
}
}
}


2.Create a new Activity XML File, Layout Folder In Project. (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:background="@drawable/common_bg"
    tools:context=".DisplayActivity" >

   <ListView
        android:id="@+id/lv_friend_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:cacheColorHint="#000000"
        android:divider="@null"
        android:dividerHeight="5dp" />

</RelativeLayout>

3.Create a new BaseAdapter File In Project. (FriendAdapter.java).

package com.valkesh.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.valkesh.baseadapterdemo.R;
import com.valkesh.model.FriendDetailsListModel;

public class FriendAdapter extends BaseAdapter implements
OnClickListener {


private Context mContext;
private ArrayList<FriendDetailsListModel> mFriendsListOriginal = new ArrayList<FriendDetailsListModel>();
private static LayoutInflater inflater = null;

public FriendAdapter(Context context,
ArrayList<FriendDetailsListModel> data) {
mContext = context;
mFriendsListOriginal = data;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
return mFriendsListOriginal.size();
}

@Override
public Object getItem(int position) {
return mFriendsListOriginal.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

static class ViewHolder {
TextView email_id, f_name, age, gender;
Button addHim;
}

public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;

LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.activity_display, null);
holder = new ViewHolder();
holder.f_name = (Button) convertView.findViewById(R.id.f_name);
holder.age = (Button) convertView.findViewById(R.id.age);
holder.gender = (Button) convertView.findViewById(R.id.gender);
holder.addHim = (Button) convertView.findViewById(R.id.trackhim);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
FriendDetailsListModel rowItem = (FriendDetailsListModel) getItem(position);

final String email_id_on = rowItem.getEmail_id();
final String name_on = rowItem.getEmail_id();

holder.f_name.setText(rowItem.getF_name());
holder.gender.setText(rowItem.getGender());
holder.age.setText(rowItem.getEmail_id());
holder.addHim.setOnClickListener(new  OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Intent intent = new Intent(mContext, XYZ.class);
// mContext.startActivity(intent);
// ((Activity) mContext).finish();
}
});
return convertView;
}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

}

}
4.Create a new BaseAdapter File, Layout Folder In Project. (activity_display.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=".DisplayActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_alignParentLeft="true"
        android:background="@drawable/valkesh" />

    <Button
        android:id="@+id/f_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:background="@drawable/bginterest"
        />

    <Button
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/f_name"
        android:background="@drawable/bginterest"
        />

    <Button
        android:id="@+id/gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/age"
        android:background="@drawable/bginterest"
       />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/gender"
        android:layout_centerHorizontal="true" >

        <Button
            android:id="@+id/trackhim"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/button_bg"
            android:text="Like Me" />
    </LinearLayout>

</RelativeLayout>
5.Create a new Model Class (POGO) Project. (FriendDetailsListModel.java).

package com.valkesh.model;

public class FriendDetailsListModel {

private String friend_id;
private String email_id;
private String f_name;
private String dob;
private String gender;
/**
* @return the friend_id
*/
public String getFriend_id() {
return friend_id;
}
/**
* @param friend_id the friend_id to set
*/
public void setFriend_id(String friend_id) {
this.friend_id = friend_id;
}
/**
* @return the email_id
*/
public String getEmail_id() {
return email_id;
}
/**
* @param email_id the email_id to set
*/
public void setEmail_id(String email_id) {
this.email_id = email_id;
}
/**
* @return the f_name
*/
public String getF_name() {
return f_name;
}
/**
* @param f_name the f_name to set
*/
public void setF_name(String f_name) {
this.f_name = f_name;
}
/**
* @return the dob
*/
public String getDob() {
return dob;
}
/**
* @param dob the dob to set
*/
public void setDob(String dob) {
this.dob = dob;
}
/**
* @return the gender
*/
public String getGender() {
return gender;
}
/**
* @param gender the gender to set
*/
public void setGender(String gender) {
this.gender = gender;
}
}