Sunday, 5 October 2014

Custom Listview images With Refresh adapter

Custom Listview images With Refresh adapter



In this tutorial we will learn to implement android custom listview which contains images and textual data. This tutorial presents an android listview with image example. Here you will learn to create your own custom adapter with the help of ArrayAdapter and refresh the list when you add new items


MainActivity.java


package com.example.customlist;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {

Button adButton;

// String color_names[] = { "red", "green", "blue", "yellow", "pink",
// "brown" };
/*
* Integer image_id[] = { R.drawable.ic_launcher, R.drawable.ic_launcher,
* R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,
* R.drawable.ic_launcher };
*/

ArrayList<String> color_names = new ArrayList<>();
ArrayList<Integer> image_id = new ArrayList<>();
Customlistadapter adapter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
color_names.add("red");
color_names.add("green");
color_names.add("blue");
color_names.add("yellow");
color_names.add("pink");

image_id.add(R.drawable.ic_launcher);
image_id.add(R.drawable.ic_launcher);
image_id.add(R.drawable.ic_launcher);
image_id.add(R.drawable.ic_launcher);
image_id.add(R.drawable.ic_launcher);

adapter = new Customlistadapter(this, image_id,
color_names);
ListView lv = (ListView) findViewById(R.id.listView);
lv.setAdapter(adapter);

adButton = (Button) findViewById(R.id.addbtn);
adButton.setOnClickListener(new OnClickListener() {

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

color_names.add("NEW VALUSE ADDED");
image_id.add(R.drawable.ic_launcher);
adapter.notifyDataSetChanged();
}
});


}

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

}


Customlistadapter.java



package com.example.customlist;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Customlistadapter extends ArrayAdapter {
/* String[] color_names;
Integer[] image_id;*/
Context context;
private ArrayList<String> color_names;
private ArrayList<Integer> image_id;

/* public Customlistadapter(Activity context, Integer[] image_id, String[] text) {
super(context, R.layout.list_row, text);
// TODO Auto-generated constructor stub
this.color_names = text;
this.image_id = image_id;
this.context = context;
}*/

public Customlistadapter(MainActivity context,
ArrayList<Integer> image_id2, ArrayList<String> color_names2) {


super(context, R.layout.list_row, color_names2);
// TODO Auto-generated constructor stub
this.color_names = color_names2;
this.image_id = image_id2;
this.context = context;

// TODO Auto-generated constructor stub
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View single_row = inflater.inflate(R.layout.list_row, null, true);
TextView textView = (TextView) single_row.findViewById(R.id.textView);
ImageView imageView = (ImageView) single_row
.findViewById(R.id.imageView);
textView.setText(color_names.get(position));
imageView.setImageResource(image_id.get(position));
return single_row;
}
}


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

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>

    <Button
        android:id="@+id/addbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/listView"
        android:layout_below="@+id/listView"
        android:layout_marginTop="17dp"
        android:text="ADD" />

</RelativeLayout>



list_row.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="horizontal" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="40dp"
        android:text="TextView" />

</LinearLayout>


Download Full source code from here

Saturday, 2 February 2013

Facebook Android Generate Key Hash

more click here
In order to generate key hash you need to follow some easy steps.
2) Make a openssl folder in C drive
3) Extract Zip files into openssl folder
4) Copy the File debug.keystore from .android folder in my case (C:\Users\SYSTEM.android) and paste into JDK bin Folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin)
5) Open command prompt and give the path of JDK Bin folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin).
6) Copy the code and hit enter keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt
7) Now you need to enter password, Password = android.
8) See in openssl Bin folder you will get a file with the name of debug.txt
9) Now either you can restart command prompt or work with existing command prompt
10) comes to C drive and give the path of openssl Bin folder
11) copy the following code and paste openssl sha1 -binary debug.txt > debug_sha.txt
12) you will get debug_sha.txt in openssl bin folder
13) Again copy following code and paste openssl base64 -in debug_sha.txt > debug_base64.txt
14) you will get debug_base64.txt in openssl bin folder
15) open debug_base64.txt file Here is your Key hash.
Download Android Codes From SkyBlueAndroid

Sunday, 2 December 2012

Get all information in a android phone

                         Get all information in a android phone





*#*#4636#*#*