tag:blogger.com,1999:blog-66060630742223606342024-03-27T22:28:16.810-07:00Android Development, Android Development Tutorial, Android Development Training in IndiaAndroid Development World offers training program on Android Application Development, Android mobile applications training, android live projects for Android beginners.Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-6606063074222360634.post-87480015382096332202013-12-08T09:13:00.001-08:002013-12-08T09:13:26.567-08:00Android Json Parsing + Sqlite Database Example<div dir="ltr" style="text-align: left;" trbidi="on">
Hello ALL,<br />
<br />
Today i created one example for Parsing JSON and store response in sqlite database and display, update and delete operations from database.<br />
<br />
<b>Menifest.xml</b><br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"<br />
package="com.samir"<br />
android:versionCode="1"<br />
android:versionName="1.0" ><br />
<br />
<uses-sdk android:minSdkVersion="8" /><br />
<br />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><br />
<uses-permission android:name="android.permission.INTERNET" /><br />
<br />
<application<br />
android:icon="@drawable/ic_launcher"<br />
android:label="@string/app_name" ><br />
<activity<br />
android:name=".MainActivity"<br />
android:label="@string/app_name"<br />
android:screenOrientation="portrait" ><br />
<intent-filter><br />
<action android:name="android.intent.action.MAIN" /><br />
<br />
<category android:name="android.intent.category.LAUNCHER" /><br />
</intent-filter><br />
</activity><br />
<activity android:name="SearchProduct" /><br />
<activity android:name="AddUpdateValues"></activity><br />
</application><br />
<br />
</manifest><br />
<br />
<br />
<b>MainActivity.java</b><br />
<br />
<br />
package com.samir;<br />
<br />
import java.util.ArrayList;<br />
import java.util.Collections;<br />
import java.util.Comparator;<br />
import java.util.List;<br />
<br />
import org.json.JSONArray;<br />
import org.json.JSONException;<br />
import org.json.JSONObject;<br />
<br />
import com.androidadvance.db.DatabaseHelper;<br />
<br />
import android.app.Activity;<br />
import android.app.AlertDialog;<br />
import android.app.ProgressDialog;<br />
import android.content.DialogInterface;<br />
import android.content.Intent;<br />
import android.os.AsyncTask;<br />
import android.os.Bundle;<br />
import android.util.Log;<br />
import android.view.View;<br />
import android.widget.AdapterView;<br />
import android.widget.AdapterView.OnItemClickListener;<br />
import android.widget.ListView;<br />
import android.widget.Toast;<br />
<br />
public class MainActivity extends Activity implements OnItemClickListener {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String rssFeed = "https://www.dropbox.com/s/rhk01nqlyj5gixl/jsonparsing.txt?dl=1";<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String ARRAY_NAME = "student";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String ID = "id";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String NAME = "name";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String CITY = "city";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String GENDER = "Gender";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String AGE = "age";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static final String BIRTH_DATE = "birthdate";<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// List<Item> arrayOfList;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ArrayList<ProductModel> arrayOfList;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ListView listView;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>NewsRowAdapter objAdapter;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>DatabaseHelper db;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onCreate(Bundle savedInstanceState) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onCreate(savedInstanceState);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>setContentView(R.layout.main);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>arrayOfList = new ArrayList<ProductModel>();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>listView = (ListView) findViewById(R.id.listview);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>listView.setOnItemClickListener(this);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// arrayOfList = new ArrayList<Item>();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (Utils.isNetworkAvailable(MainActivity.this)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>new MyTask().execute(rssFeed);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>showToast("No Network Connection!!!");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void Search(View v) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>startActivity(new Intent(MainActivity.this, SearchProduct.class));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
//<span class="Apple-tab-span" style="white-space: pre;"> </span>public void Update(View v)<br />
//<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
//<span class="Apple-tab-span" style="white-space: pre;"> </span>startActivity(new Intent(MainActivity.this,AddUpdateValues.class));<br />
//<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// My AsyncTask start...<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>class MyTask extends AsyncTask<String, Void, String> {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ProgressDialog pDialog;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onPreExecute() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onPreExecute();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDialog = new ProgressDialog(MainActivity.this);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDialog.setMessage("Loading...");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDialog.setCancelable(false);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDialog.show();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected String doInBackground(String... params) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return Utils.getJSONString(params[0]);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onPostExecute(String result) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onPostExecute(result);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (null != pDialog && pDialog.isShowing()) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDialog.dismiss();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (null == result || result.length() == 0) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>showToast("No data found from web!!!");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>MainActivity.this.finish();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>JSONObject mainJson = new JSONObject(result);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>JSONArray jsonArray = mainJson.getJSONArray(ARRAY_NAME);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db = new DatabaseHelper(MainActivity.this);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.getWritableDatabase();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.emptyProduct();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (int i = 0; i < jsonArray.length(); i++) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>JSONObject objJson = jsonArray.getJSONObject(i);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductModel prod = new ProductModel();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>prod.productname = objJson.getString(NAME);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>prod.productprice = objJson.getString(CITY);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//prod.idno= objJson.getString(ID);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>prod.setProductname(objJson.getString(NAME));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>prod.setProductprice(objJson.getString(CITY));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//prod.setIdno(objJson.getString(ID));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("-----size-----",<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>"-----size-----" + objJson.getString(NAME));<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.addProduct(prod);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Item objItem = new Item();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setId(objJson.getInt(ID));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setName(objJson.getString(NAME));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setCity(objJson.getString(CITY));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setGender(objJson.getString(GENDER));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setAge(objJson.getInt(AGE));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// objItem.setBirthdate(objJson.getString(BIRTH_DATE));<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// arrayOfList.add(prod);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (JSONException e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// check data...<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>/*<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * for (int i = 0; i < arrayOfList.size(); i++) { Item item =<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * arrayOfList.get(i); System.out.println(item.getId());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> *<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getId());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getName());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getCity());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getGender());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getAge());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> * System.out.println(item.getBirthdate()); }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> */<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Collections.sort(arrayOfList, new Comparator<Item>() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// @Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// public int compare(Item lhs, Item rhs) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// return (lhs.getAge() - rhs.getAge());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// });<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>setAdapterToListview();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onItemClick(AdapterView<?> parent, View view, int position,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>long id) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>showDeleteDialog(position);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void showDeleteDialog(final int position) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.create();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alertDialog.setTitle("Delete ??");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alertDialog.setMessage("Are you sure want to Delete it??");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// db. removeProduct(prod);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alertDialog.setButton("No", new DialogInterface.OnClickListener() {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onClick(DialogInterface dialog, int which) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>dialog.dismiss();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>});<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alertDialog.setButton2("Yes", new DialogInterface.OnClickListener() {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onClick(DialogInterface dialog, int which) {<br />
<br />
//<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductModel model = new ProductModel();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String name = arrayOfList.get(position).getProductname();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db = new DatabaseHelper(MainActivity.this);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.getWritableDatabase();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.removeProduct(name);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>arrayOfList.remove(position);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>objAdapter.notifyDataSetChanged();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>});<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alertDialog.show();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void setAdapterToListview() {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db = new DatabaseHelper(MainActivity.this);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.getWritableDatabase();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>arrayOfList.clear();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>arrayOfList = db.getProudcts();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("-----size-----", "-----size-----" + arrayOfList.size());<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>objAdapter = new NewsRowAdapter(MainActivity.this, R.layout.row,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>arrayOfList);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>listView.setAdapter(objAdapter);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void showToast(String msg) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
}<br />
<br />
<br />
<br />
<b>NewsRowAdapter.java</b><br />
<b><br /></b>
package com.samir;<br />
<br />
import java.util.List;<br />
<br />
import android.app.Activity;<br />
import android.content.Context;<br />
import android.text.Html;<br />
import android.view.LayoutInflater;<br />
import android.view.View;<br />
import android.view.ViewGroup;<br />
import android.widget.ArrayAdapter;<br />
import android.widget.TextView;<br />
<br />
public class NewsRowAdapter extends ArrayAdapter<ProductModel> {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private Activity activity;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private List<ProductModel> items;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private ProductModel objBean;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private int row;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public NewsRowAdapter(Activity act, int resource, List<ProductModel> arrayList) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>super(act, resource, arrayList);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.activity = act;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.row = resource;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.items = arrayList;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public View getView(final int position, View convertView, ViewGroup parent) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>View view = convertView;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ViewHolder holder;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (view == null) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>LayoutInflater inflater = (LayoutInflater) activity<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>view = inflater.inflate(row, null);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder = new ViewHolder();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>view.setTag(holder);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder = (ViewHolder) view.getTag();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if ((items == null) || ((position + 1) > items.size()))<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return view;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>objBean = items.get(position);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvName = (TextView) view.findViewById(R.id.tvname);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvCity = (TextView) view.findViewById(R.id.tvcity);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvBDate = (TextView) view.findViewById(R.id.tvbdate);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvGender = (TextView) view.findViewById(R.id.tvgender);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvAge = (TextView) view.findViewById(R.id.tvage);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvCity.setText(Html.fromHtml(objBean.getProductname()));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>holder.tvName.setText(Html.fromHtml(objBean.getProductprice()));<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return view;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public class ViewHolder {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public TextView tvName, tvCity, tvBDate, tvGender, tvAge;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
}<br />
<br />
<br />
<b>ProductModel.java</b><br />
<b><br /></b>
package com.samir;<br />
<br />
public class ProductModel {<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public String getProductname() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return productname;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void setProductname(String productname) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.productname = productname;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public String getProductprice() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return productprice;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void setProductprice(String productprice) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.productprice = productprice;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public String idno="", productname="", productprice="";<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public String getIdno() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return idno;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void setIdno(String idno) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.idno = idno;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>SearchProduct.java</b></div>
<div>
<b><br /></b></div>
<div>
<div>
package com.samir;</div>
<div>
<br /></div>
<div>
import java.util.ArrayList;</div>
<div>
import java.util.List;</div>
<div>
<br /></div>
<div>
import com.androidadvance.db.DatabaseHelper;</div>
<div>
<br /></div>
<div>
import android.app.Activity;</div>
<div>
import android.content.Context;</div>
<div>
import android.graphics.Color;</div>
<div>
import android.os.AsyncTask;</div>
<div>
import android.os.Bundle;</div>
<div>
import android.os.Handler;</div>
<div>
import android.text.Editable;</div>
<div>
import android.text.TextWatcher;</div>
<div>
import android.util.Log;</div>
<div>
import android.view.LayoutInflater;</div>
<div>
import android.view.View;</div>
<div>
import android.view.ViewGroup;</div>
<div>
import android.widget.ArrayAdapter;</div>
<div>
import android.widget.AutoCompleteTextView;</div>
<div>
import android.widget.BaseAdapter;</div>
<div>
import android.widget.EditText;</div>
<div>
import android.widget.ImageView;</div>
<div>
import android.widget.ListView;</div>
<div>
import android.widget.ProgressBar;</div>
<div>
import android.widget.RelativeLayout;</div>
<div>
import android.widget.TextView;</div>
<div>
import android.widget.Toast;</div>
<div>
<br /></div>
<div>
public class SearchProduct extends Activity implements TextWatcher {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>EditText _searchbox;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private ProgressBar showprogress;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>searchtask dotask;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private ArrayList<ProductModel> _productList;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ListView _listview;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>DatabaseHelper db;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public AutoCompleteTextView myAutoComplete;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private ArrayList<ProductModel> _productList_Temp;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String query = "";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ArrayList<ProductModel> modelarray;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onCreate(Bundle savedInstanceState) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onCreate(savedInstanceState);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>setContentView(R.layout.searchproduct);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db = new DatabaseHelper(getApplicationContext());</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>modelarray=new ArrayList<ProductModel>();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>modelarray.clear();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>modelarray = db.getProudcts();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("-----size-----", "-----size-----" + modelarray.size());</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_searchbox = (EditText) findViewById(R.id.txtsearchproduct);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>showprogress = (ProgressBar) findViewById(R.id.showprogress);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_listview = (ListView) findViewById(R.id.searchlistview);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_searchbox.addTextChangedListener(textwatcher);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Runnable runn = new Runnable() {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void run() {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>handlersearch.sendEmptyMessage(0);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>};</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>TextWatcher textwatcher = new TextWatcher() {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onTextChanged(CharSequence s, int start, int before,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int count) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.i("---onTextChanged ----", "---------onTextChanged ----");</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (_searchbox.getText().toString().length() > 1) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>query = _searchbox.getText().toString().replace(" ", "%20");</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>handlersearch.removeCallbacks(runn);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>handlersearch.post(runn);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>showprogress.setVisibility(View.GONE);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (dotask != null) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (dotask.getStatus().equals(AsyncTask.Status.RUNNING)) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>dotask.cancel(true);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>handlersearch.removeCallbacks(runn);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList = new ArrayList<ProductModel>();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList.clear();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_listview.setAdapter(new CustomBaseAdapter(SearchProduct.this,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList));</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void beforeTextChanged(CharSequence s, int start, int count,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int after) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void afterTextChanged(Editable s) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>};</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Handler handlersearch = new Handler() {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void handleMessage(android.os.Message msg) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>dotask = new searchtask();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>dotask.execute();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>};</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>};</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private class searchtask extends AsyncTask<Void, Void, Void> {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onPreExecute() {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>showprogress.setVisibility(View.VISIBLE);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>};</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onPostExecute(Void param) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// animation.dismiss();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>showprogress.setVisibility(View.GONE);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (_productList == null)</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ArrayList<String> item = new ArrayList<String>();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (int i = 0; i < _productList.size(); i++) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.add(_productList.get(i).productname);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>myAutoComplete = (AutoCompleteTextView) findViewById(R.id.myautocomplete);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>myAutoComplete.addTextChangedListener(SearchProduct.this);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>myAutoComplete.setAdapter(new ArrayAdapter<String>(</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SearchProduct.this,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>android.R.layout.simple_dropdown_item_1line, item));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList_Temp = new ArrayList<ProductModel>();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (int i = 0; i < _productList.size(); i++) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList_Temp.add(_productList.get(i));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_listview.setAdapter(new CustomBaseAdapter(SearchProduct.this,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList_Temp));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected Void doInBackground(Void... params) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db = new DatabaseHelper(getApplicationContext());</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ArrayList<ProductModel> product_list = db.getProudcts(query);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("product_list.size>>>>>" + product_list.size());</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (int i = 0; i < product_list.size(); i++) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String tidno = product_list.get(i).getIdno();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("tidno>>>>>" + tidno);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String tname = product_list.get(i).getProductname();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String tprice = product_list.get(i).getProductprice();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductModel _ProductModel = new ProductModel();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_ProductModel.setIdno(tidno);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_ProductModel.setProductname(tname);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_ProductModel.setProductprice(tprice);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_productList.add(_ProductModel);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// _productList = _parser.getProductList();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return null;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private class CustomBaseAdapter extends BaseAdapter {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>LayoutInflater _inflater;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>List<ProductModel> productList;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public CustomBaseAdapter(Context context, List<ProductModel> productList) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_inflater = LayoutInflater.from(context);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>this.productList = productList;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public int getCount() {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return productList.size();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public Object getItem(int position) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return position;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public long getItemId(int position) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return position;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public View getView(int position, View convertView, ViewGroup parent) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ViewHolder _holder;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (convertView == null) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>convertView = _inflater.inflate(R.layout.product_list, null);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder = new ViewHolder();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder.title = (TextView) convertView</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.findViewById(R.id.txt_title_text);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder.price = (TextView) convertView</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.findViewById(R.id.txt_price);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>convertView.setTag(_holder);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder = (ViewHolder) convertView.getTag();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder.title.setText(productList.get(position).productname.trim());</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>_holder.price.setText(productList.get(position).productprice);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return convertView;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private class ViewHolder {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>TextView title;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>TextView price;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void afterTextChanged(Editable arg0) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void beforeTextChanged(CharSequence s, int start, int count,</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int after) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onTextChanged(CharSequence s, int start, int before, int count) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
}</div>
<div style="font-weight: bold;">
<br /></div>
</div>
<div style="font-weight: bold;">
<br /></div>
<div>
<b>Utils.java</b></div>
<div>
<b><br /></b></div>
<div>
<div>
package com.samir;</div>
<div>
<br /></div>
<div>
import java.io.ByteArrayOutputStream;</div>
<div>
import java.io.InputStream;</div>
<div>
import java.net.HttpURLConnection;</div>
<div>
import java.net.URL;</div>
<div>
<br /></div>
<div>
import android.app.Activity;</div>
<div>
import android.content.Context;</div>
<div>
import android.net.ConnectivityManager;</div>
<div>
import android.net.NetworkInfo;</div>
<div>
<br /></div>
<div>
public class Utils {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String getJSONString(String url) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String jsonString = null;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpURLConnection linkConnection = null;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>URL linkurl = new URL(url);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>linkConnection = (HttpURLConnection) linkurl.openConnection();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int responseCode = linkConnection.getResponseCode();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (responseCode == HttpURLConnection.HTTP_OK) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>InputStream linkinStream = linkConnection.getInputStream();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ByteArrayOutputStream baos = new ByteArrayOutputStream();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int j = 0;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>while ((j = linkinStream.read()) != -1) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>baos.write(j);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>byte[] data = baos.toByteArray();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>jsonString = new String(data);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} finally {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (linkConnection != null) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>linkConnection.disconnect();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return jsonString;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static boolean isNetworkAvailable(Activity activity) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ConnectivityManager connectivity = (ConnectivityManager) activity</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getSystemService(Context.CONNECTIVITY_SERVICE);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (connectivity == null) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>NetworkInfo[] info = connectivity.getAllNetworkInfo();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (info != null) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for (int i = 0; i < info.length; i++) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (info[i].getState() == NetworkInfo.State.CONNECTED) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return true;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
}</div>
<div style="font-weight: bold;">
<br /></div>
</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<br /></div>
<div>
<b>DatabaseHelper.java</b></div>
<div>
<b><br /></b></div>
<div>
<div>
package com.androidadvance.db;</div>
<div>
<br /></div>
<div>
import java.util.ArrayList;</div>
<div>
import java.util.HashMap;</div>
<div>
import java.util.Iterator;</div>
<div>
<br /></div>
<div>
import com.samir.ProductModel;</div>
<div>
<br /></div>
<div>
import android.content.ContentValues;</div>
<div>
import android.content.Context;</div>
<div>
import android.content.SharedPreferences;</div>
<div>
import android.database.Cursor;</div>
<div>
import android.database.sqlite.SQLiteDatabase;</div>
<div>
import android.database.sqlite.SQLiteOpenHelper;</div>
<div>
import android.util.Log;</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
public class DatabaseHelper extends SQLiteOpenHelper {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String DATABASENAME = "androidadvancesqlite";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String PRODUCTTABLE = "products";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String colProductId = "id";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String _colProductid = "productidno";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String colProductName = "productname";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static String colProductPrice = "productprice";</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>private ArrayList<ProductModel> cartList = new ArrayList<ProductModel>();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Context c;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public DatabaseHelper(Context context) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>super(context, DATABASENAME, null, 33);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>c = context;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onCreate(SQLiteDatabase db) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.execSQL("CREATE TABLE if not exists producttable(id INTEGER PRIMARY KEY AUTOINCREMENT,"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ "productidno"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ " TEXT ,"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ "productname"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ " TEXT,"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ "productprice" + " TEXT)");</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.execSQL("DROP TABLE IF EXISTS" + PRODUCTTABLE);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>onCreate(db);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void addProduct(ProductModel productitem) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SQLiteDatabase db = this.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ContentValues contentValues = new ContentValues();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>contentValues.put("productidno", productitem.idno);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>contentValues.put("productname", productitem.productname);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>contentValues.put("productprice", productitem.productprice);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.insert("producttable", null, contentValues);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("-----size-----", "-----size-----" + productitem.productname);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// update</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void updateProduct(ProductModel productList) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SQLiteDatabase db = this.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ContentValues contentValues = new ContentValues();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>contentValues.put("productname", productList.productname);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>contentValues.put("productprice", productList.productprice);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.update("producttable", contentValues, "productidno="</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ productList.idno, null);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void emptyProduct() {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SQLiteDatabase db = this.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.execSQL("delete from producttable");</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void removeProduct(String productname) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>String[] args = { productname };</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>getWritableDatabase().delete("producttable", "productname=?", args);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public ArrayList<ProductModel> getProudcts() {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cartList.clear();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SQLiteDatabase db = this.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Cursor cursor = db.rawQuery("select * from producttable", null);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (cursor.getCount() != 0) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (cursor.moveToFirst()) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>do {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductModel item = new ProductModel();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.idno = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productidno"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.productname = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productname"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.productprice = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productprice"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cartList.add(item);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} while (cursor.moveToNext());</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cursor.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return cartList;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>public ArrayList<ProductModel> getProudcts(String record) {</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cartList.clear();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SQLiteDatabase db = this.getWritableDatabase();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Cursor cursor = db.query(true, "producttable", new String[] {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>"productidno", "productname", "productprice" }, "productname"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ "=?", new String[] { record }, null, null, null, null);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (cursor.getCount() != 0) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (cursor.moveToFirst()) {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>do {</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductModel item = new ProductModel();</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.idno = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productidno"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.productname = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productname"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>item.productprice = cursor.getString(cursor</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getColumnIndex("productprice"));</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cartList.add(item);</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>} while (cursor.moveToNext());</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cursor.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>db.close();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return cartList;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
}</div>
<div style="font-weight: bold;">
<br /></div>
</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
main.xml</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<br /></div>
<div>
<div>
<?xml version="1.0" encoding="utf-8"?></div>
<div>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="fill_parent"</div>
<div>
android:orientation="vertical" ></div>
<div>
<br /></div>
<div>
<ListView</div>
<div>
android:id="@+id/listview" android:layout_weight="1"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content"</div>
<div>
></div>
<div>
</ListView></div>
<div>
</div>
<div>
<Button android:text="search" android:onClick="Search"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content" </div>
<div>
/></div>
<div>
<Button android:text="update"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content" </div>
<div>
/></div>
<div>
</LinearLayout></div>
</div>
<div>
<br /></div>
<div>
<b>product_list.xml</b></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
<?xml version="1.0" encoding="utf-8"?></div>
<div>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"</div>
<div>
android:id="@+id/category_list_id"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content"</div>
<div>
android:background="@android:color/white"</div>
<div>
android:paddingBottom="1dp" ></div>
<div>
<br /></div>
<div>
<LinearLayout</div>
<div>
android:id="@+id/ll_place_name_use"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content"</div>
<div>
android:layout_centerVertical="true"</div>
<div>
android:layout_marginLeft="10dp"</div>
<div>
android:layout_marginTop="10dp"</div>
<div>
android:orientation="vertical"</div>
<div>
android:paddingRight="8dp" ></div>
<div>
<br /></div>
<div>
<TextView</div>
<div>
android:id="@+id/txt_title_text"</div>
<div>
android:layout_width="wrap_content"</div>
<div>
android:layout_height="wrap_content"</div>
<div>
android:maxLines="3"</div>
<div>
android:padding="2dp"</div>
<div>
android:text="aaa"</div>
<div>
android:textColor="@android:color/black"</div>
<div>
android:textSize="16sp"</div>
<div>
android:textStyle="bold" ></div>
<div>
</TextView></div>
<div>
<br /></div>
<div>
<TextView</div>
<div>
android:id="@+id/txt_price"</div>
<div>
android:layout_width="fill_parent"</div>
<div>
android:layout_height="wrap_content"</div>
<div>
android:layout_weight="1"</div>
<div>
android:padding="2dp"</div>
<div>
android:text="1000"</div>
<div>
android:textColor="@android:color/black"</div>
<div>
android:textSize="14sp"</div>
<div>
android:visibility="visible" ></div>
<div>
</TextView></div>
<div>
</LinearLayout></div>
<div>
<br /></div>
<div>
</RelativeLayout></div>
</div>
<br />
<b>row.xml</b><br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:id="@+id/relativelay"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:background="@drawable/list_bg"<br />
android:orientation="vertical" ><br />
<br />
<TextView<br />
android:id="@+id/tvname"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentTop="true"<br />
android:layout_marginLeft="5dip"<br />
android:maxLines="1"<br />
android:text=""<br />
android:textColor="@android:color/black"<br />
android:textSize="14dp"<br />
android:textStyle="bold" ><br />
</TextView><br />
<br />
<TextView<br />
android:id="@+id/tvcity"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentLeft="true"<br />
android:layout_below="@+id/tvname"<br />
android:layout_marginLeft="5dip"<br />
android:layout_marginTop="3dip"<br />
android:maxLines="1"<br />
android:text=""<br />
android:textColor="@android:color/black"<br />
android:textSize="14dp" ><br />
</TextView><br />
<br />
<TextView<br />
android:id="@+id/tvbdate"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentLeft="true"<br />
android:layout_below="@+id/tvcity"<br />
android:layout_marginLeft="5dip"<br />
android:layout_marginTop="3dip"<br />
android:maxLines="1"<br />
android:text=""<br />
android:textColor="@android:color/black"<br />
android:textSize="14dp" ><br />
</TextView><br />
<br />
<TextView<br />
android:id="@+id/tvgender"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentRight="true"<br />
android:layout_alignParentTop="true"<br />
android:layout_marginRight="15dip"<br />
android:maxLines="1"<br />
android:text=""<br />
android:textColor="@android:color/black"<br />
android:textSize="14dp"<br />
android:textStyle="bold" ><br />
</TextView><br />
<br />
<TextView<br />
android:id="@+id/tvage"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentRight="true"<br />
android:layout_below="@+id/tvgender"<br />
android:layout_marginRight="15dip"<br />
android:layout_marginTop="3dip"<br />
android:maxLines="1"<br />
android:text=""<br />
android:textColor="@android:color/black"<br />
android:textSize="14dp" ><br />
</TextView><br />
<br />
</RelativeLayout><br />
<br />
<b>searchproduct.xml</b><br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:id="@+id/searchlinear"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:gravity="center_horizontal"<br />
android:orientation="vertical" ><br />
<br />
<LinearLayout<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:orientation="horizontal" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:layout_weight="1"<br />
android:gravity="center"<br />
android:text="Search Record"<br />
android:textSize="18dp"<br />
android:textStyle="bold" /><br />
<br />
<ProgressBar<br />
android:id="@+id/showprogress"<br />
style="?android:attr/progressBarStyleSmall"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_marginTop="10dp"<br />
android:paddingRight="10dp"<br />
android:visibility="gone" /><br />
</LinearLayout><br />
<br />
<EditText<br />
android:id="@+id/txtsearchproduct"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:hint="search"<br />
android:lines="1"<br />
android:paddingLeft="25dp"<br />
android:visibility="visible" ><br />
</EditText><br />
<br />
<AutoCompleteTextView<br />
android:id="@+id/myautocomplete"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:completionThreshold="1"<br />
android:hint="search"<br />
android:lines="1"<br />
android:visibility="gone" /><br />
<br />
<ListView<br />
android:id="@+id/searchlistview"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content" ><br />
</ListView><br />
<br />
</LinearLayout><br />
<br />
<br />
<br />
<a href="https://www.mediafire.com/?dv3ab6lzdh8y9a0">Download Source Code </a></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com16tag:blogger.com,1999:blog-6606063074222360634.post-10863948480305770022013-10-27T22:29:00.003-07:002013-12-03T00:53:44.001-08:00How to call HTTPS webservices in android<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<br />
<br />
For Example :<br />
<br />
==> First call following method.<br />
<br />
public static void trustAllHosts() {<br /><br /> X509TrustManager easyTrustManager = new X509TrustManager() {<br /><br /> public void checkClientTrusted(X509Certificate[] chain,<br /> String authType) throws CertificateException {<br /> // Oh, I am easy!<br /> }<br /><br /> public void checkServerTrusted(X509Certificate[] chain,<br /> String authType) throws CertificateException {<br /> // Oh, I am easy!<br /> }<br /><br /> public X509Certificate[] getAcceptedIssuers() {<br /> return null;<br /> }<br /><br /> };<br /><br /> // Create a trust manager that does not validate certificate chains<br /> TrustManager[] trustAllCerts = new TrustManager[] { easyTrustManager };<br /><br /> // Install the all-trusting trust manager<br /> try {<br /> SSLContext sc = SSLContext.getInstance("TLS");<br /><br /> sc.init(null, trustAllCerts, new java.security.SecureRandom());<br /><br /> HttpsURLConnection<br /> .setDefaultSSLSocketFactory(sc.getSocketFactory());<br /><br /> } catch (Exception e) {<br /> e.printStackTrace();<br /> }<br /> }<br />
<br />
====> After this<br />
<br />
<br />
For calling<span style="font-family: inherit;"> HTTPS webservices you need</span> to create Custom HttpClient instead of using DefaultHttpClient.<br />
<br />
<br />
HttpClient _httpclient = Utils.getNewHttpClient();<br />
<br />
Following is getNewHttpClient() method :<br />
<br />
<br />
<style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style>
<br />
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;">public
static HttpClient getNewHttpClient() {</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> try
{</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> KeyStore
trustStore = KeyStore.getInstance(KeyStore</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> .getDefaultType());</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> trustStore.load(null,
null);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> SSLSocketFactory
sf = new MySSLSocketFactory(trustStore);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> HttpParams
params = new BasicHttpParams();</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> HttpProtocolParams.setVersion(params,
HttpVersion.HTTP_1_1);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> HttpProtocolParams.setContentCharset(params,
HTTP.UTF_8);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> SchemeRegistry
registry = new SchemeRegistry();</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> registry.register(new
Scheme("http", PlainSocketFactory</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> .getSocketFactory(),
80));</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> registry.register(new
Scheme("https", sf, 443));</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> ClientConnectionManager
ccm = new ThreadSafeClientConnManager(</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> params,
registry);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> return
new DefaultHttpClient(ccm, params);</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }
catch (Exception e) {</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> return
new DefaultHttpClient();</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<br />
<style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style>
<br />
<div style="font-family: inherit; margin-bottom: 0cm; text-align: left;">
<span style="color: black; font-size: small;">Here
we have use custom MySSLSocketFactory class, which is following. </span>
</div>
<div style="font-family: inherit; margin-bottom: 0cm; text-align: left;">
<span style="font-size: small;"><br /></span></div>
<div style="font-family: inherit; margin-bottom: 0cm; text-align: left;">
<span style="color: black; font-size: small;">Create
new class MySSLSocketFactory.java copy following code and paste.</span></div>
<span style="font-size: small;"><br /></span>
<br />
<span style="font-size: small;"><br /></span>
<br />
<span style="font-size: small;"><br /></span>
<br />
<style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style>
<br />
<div style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"><span style="color: #7f0055;"><b>public</b></span>
<span style="color: #7f0055;"><b>class</b></span> MySSLSocketFactory <span style="color: #7f0055;"><b>extends</b></span>
SSLSocketFactory {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> SSLContext
</span><span style="color: #0000c0;">sslContext</span><span style="color: black;">
= SSLContext.</span><span style="color: black;"><i>getInstance</i></span><span style="color: black;">(</span><span style="color: #2a00ff;">"TLS"</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
MySSLSocketFactory(KeyStore truststore)</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>throws</b></span><span style="color: black;">
NoSuchAlgorithmException, KeyManagementException,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> KeyStoreException,
UnrecoverableKeyException {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">(truststore);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> TrustManager
tm = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
X509TrustManager() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
checkClientTrusted(X509Certificate[] chain,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> String
authType) </span><span style="color: #7f0055;"><b>throws</b></span><span style="color: black;">
CertificateException {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
checkServerTrusted(X509Certificate[] chain,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> String
authType) </span><span style="color: #7f0055;"><b>throws</b></span><span style="color: black;">
CertificateException {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
X509Certificate[] getAcceptedIssuers() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>return</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>null</b></span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> };</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #0000c0;">sslContext</span><span style="color: black;">.init(</span><span style="color: #7f0055;"><b>null</b></span><span style="color: black;">,
</span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
TrustManager[] { tm }, </span><span style="color: #7f0055;"><b>null</b></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
Socket createSocket(Socket socket, String host, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
port,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>boolean</b></span><span style="color: black;">
autoClose) </span><span style="color: #7f0055;"><b>throws</b></span><span style="color: black;">
IOException, UnknownHostException {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>return</b></span><span style="color: black;">
</span><span style="color: #0000c0;">sslContext</span><span style="color: black;">.getSocketFactory().createSocket(socket,
host, port,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> autoClose);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-size: large;"><br /></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
Socket createSocket() </span><span style="color: #7f0055;"><b>throws</b></span><span style="color: black;">
IOException {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monospace; font-size: large;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>return</b></span><span style="color: black;">
</span><span style="color: #0000c0;">sslContext</span><span style="color: black;">.getSocketFactory().createSocket();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-size: large;"><span style="font-family: Monospace;">}</span></span><br />
<br />
<span style="color: black; font-size: large;"><span style="font-family: Monospace;">Now done :) You can parse your xml now. </span></span><br />
<br />
<br />
<span style="color: black; font-size: large;"><span style="font-family: Monospace;"><br /></span></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com19tag:blogger.com,1999:blog-6606063074222360634.post-57902657884861597032013-08-11T23:18:00.001-07:002013-08-12T05:27:47.573-07:00Using multiple text colors in Android's textview<div dir="ltr" style="text-align: left;" trbidi="on">
I had faced on issue in my past project. How to set multiple colors in single textview ? For that I have solve it using following way. <br />
<br />
productprice.setText(Html.fromHtml("Price" + ": "<br />
+ "<font color=\"#990000\">"<br />
<br />
+ cartList.get(position).ProductPrice + " " + "</font>"));<br />
<br />
<br />
productprice is TextView, set android:textColor as default color for Textview. <br />
<br />
<br />
Hope it helps you also.</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-32826196669000922592013-05-01T23:54:00.001-07:002013-05-02T05:13:49.185-07:00What does “xmlns” in Android XML mean?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;">Generally we write following line in android xml file.</span><br />
<pre class="lang-xml prettyprint prettyprinted"><span style="font-size: large;"><code><span class="pln">xmlns:android="http://schemas.android.com/apk/res/android"</span></code></span></pre>
<br />
It defines <a href="http://www.w3.org/TR/REC-xml-names/" target="_blank">XML Namespace.</a><br />
<br />
The <b>Namespace Prefix</b> is "<i>android</i>" and the <b>Namespace URI</b> is "<i><a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a></i>"<br />
<br />
Basically, every element (or attribute) in xml belongs to a namespace, a way of "qualifying" the name of the element.<br />
<br />
<b>Example :</b><br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" </div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com1tag:blogger.com,1999:blog-6606063074222360634.post-55147340986100136072013-04-17T03:45:00.001-07:002013-04-17T03:45:02.911-07:00Select + copy text in a TextView?<div dir="ltr" style="text-align: left;" trbidi="on">
Generally we can copy / paste the value from EditText by long click. It is in-build functionality of Android. Now lets say you have requirement same thing in TextView. Then you have to use <a href="http://developer.android.com/reference/android/app/Activity.html#registerForContextMenu%28android.view.View%29" target="_blank">registerForContextMenu</a>.<br />
<br />
<br />
Like registerForContextMenu(yourtextview);<br />
<br />
and your TextView will be registered for receiving context menu events.<br />
<br />
Then You have to override onCreateContextMenu() method. Following is entire code.<br />
<br />
<br />
@Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> txtcopytext = (TextView) findViewById(R.id.txtcopytext);<br /> registerForContextMenu(txtcopytext);<br /><br /> }<br /><br /> @Override<br /> public void onCreateContextMenu(ContextMenu menu, View v,<br /> ContextMenuInfo menuInfo) {<br /> // user has long pressed your TextView<br /> menu.add(0, v.getId(), 0,<br /> "Copy");<br /><br /> // cast the received View to TextView so that you can get its text<br /> TextView yourTextView = (TextView) v;<br /><br /> // place your TextView's text in clipboard<br /> ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);<br /> clipboard.setText(yourTextView.getText());<br /> }<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi675yrbdTPwgWmVbetkwxroold8AWK8aJgC9J3Rd-dAKa9NT81SmLPw-XGR5rQI_gk6I_JxgMB3otHZr1JR74ym2rnW35BESAonCJ0n7RPo9mIoNZIiCD_5UwiDeCqbs6oMSJAbAkxSIA/s1600/device-2013-04-17-161218.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi675yrbdTPwgWmVbetkwxroold8AWK8aJgC9J3Rd-dAKa9NT81SmLPw-XGR5rQI_gk6I_JxgMB3otHZr1JR74ym2rnW35BESAonCJ0n7RPo9mIoNZIiCD_5UwiDeCqbs6oMSJAbAkxSIA/s320/device-2013-04-17-161218.png" width="192" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoga5RAW7QwVIwDcHl9UZnzJCQ_ocJx5MoV1xC6qrT2CtXiA-i0hQOX34C_zqIWIGflFMLSmS57gaCLnajVQwhfhTMKhc-E6xkgEqdpmrlInr2abM_wtQujDAJCswV9Img08VhbP0iPmk/s1600/device-2013-04-17-161237.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a> <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi675yrbdTPwgWmVbetkwxroold8AWK8aJgC9J3Rd-dAKa9NT81SmLPw-XGR5rQI_gk6I_JxgMB3otHZr1JR74ym2rnW35BESAonCJ0n7RPo9mIoNZIiCD_5UwiDeCqbs6oMSJAbAkxSIA/s1600/device-2013-04-17-161218.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk3ICS655JkcRsi3e0p0mQBnzk99UsPOk0b6xFiJr5F2xdKHEU8SoZdWnd-9kyL4esXr9rmXuyT7rAwvUSfajfdMSI1CuQ5aWIXbJ5sJoBMB6EgUfrZmPF9lUbAmgyDEBFkrE6vUx2zlw/s1600/device-2013-04-17-161237.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoga5RAW7QwVIwDcHl9UZnzJCQ_ocJx5MoV1xC6qrT2CtXiA-i0hQOX34C_zqIWIGflFMLSmS57gaCLnajVQwhfhTMKhc-E6xkgEqdpmrlInr2abM_wtQujDAJCswV9Img08VhbP0iPmk/s1600/device-2013-04-17-161237.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoga5RAW7QwVIwDcHl9UZnzJCQ_ocJx5MoV1xC6qrT2CtXiA-i0hQOX34C_zqIWIGflFMLSmS57gaCLnajVQwhfhTMKhc-E6xkgEqdpmrlInr2abM_wtQujDAJCswV9Img08VhbP0iPmk/s320/device-2013-04-17-161237.png" width="192" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi675yrbdTPwgWmVbetkwxroold8AWK8aJgC9J3Rd-dAKa9NT81SmLPw-XGR5rQI_gk6I_JxgMB3otHZr1JR74ym2rnW35BESAonCJ0n7RPo9mIoNZIiCD_5UwiDeCqbs6oMSJAbAkxSIA/s1600/device-2013-04-17-161218.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> </a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk3ICS655JkcRsi3e0p0mQBnzk99UsPOk0b6xFiJr5F2xdKHEU8SoZdWnd-9kyL4esXr9rmXuyT7rAwvUSfajfdMSI1CuQ5aWIXbJ5sJoBMB6EgUfrZmPF9lUbAmgyDEBFkrE6vUx2zlw/s1600/device-2013-04-17-161237.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb0JvBJglWN63lr8NcI4-B_3MDjjf2452zpHaiHXwQzBX6npE58x0zOZmD45lKiA2BzRtaghT26mx674PX_ZtevsPk3n4hgKfLROk-BKDQhATkxnjOMqvnyFd4R5rxu7slziAlAbVcAQ0/s1600/device-2013-04-17-161218.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com4tag:blogger.com,1999:blog-6606063074222360634.post-57607437391155597722013-04-15T23:01:00.003-07:002013-04-15T23:05:52.235-07:00How to set background color with borders to perticular View dynamically in android<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Hello, Today I will explain you how to set background color + borders to particular view in android.<br />
<br />
Let's say You have one button and you have to set background color RED with border color gray, for that you have to use <a href="http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html" target="_blank">GradientDrawable</a>.<br />
<br />
<br />
<pre class="default prettyprint prettyprinted"><code><span class="pln"> <span id="goog_1553545825"></span>GradientDrawable<span id="goog_1553545826"></span> drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setCornerRadius(10);
drawable.setStroke(2, Color.GRAY);
drawable.setColor(Color.RED));</span><span class="pun"> </span></code></pre>
<pre class="default prettyprint prettyprinted"><code><span class="pun"> </span></code></pre>
<pre class="default prettyprint prettyprinted"><code><span class="pln"> btnBlackColor</span><span class="pun">.</span><span class="pln">setBackgroundDrawable</span><span class="pun">(</span><span class="pln">drawable</span><span class="pun">);</span></code>
</pre>
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-25367020230615579462013-04-11T04:08:00.002-07:002013-04-11T23:33:02.740-07:00How to put imageview on another imageview tranperent ? <div dir="ltr" style="text-align: left;" trbidi="on">
Hello,<br />
<br />
Today I explain how to put ImageView on another ImageView as Transparent.<br />
<br />
Following is an xml file.<br />
<br />
<b>main.xml</b><br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent" ><br />
<br />
<ImageView
<br />
android:id="@+id/first"
<br />
android:layout_width="fill_parent"
<br />
android:layout_height="fill_parent"
<br />
android:src="@drawable/ic_launcher" >
<br />
</ImageView>
<br />
<br />
<ImageView
<br />
android:id="@+id/second"
<br />
android:layout_width="fill_parent"
<br />
android:layout_height="fill_parent" <br />
android:background="@android:color/transparent"
android:src="@drawable/bg4" /><br />
</FrameLayout><br />
<br />
<br />
Following is JAVA file.<br />
<br />
<b>TransperentViewOnAnotherViewActivity.java</b><br />
<br />
<pre name="code">public class TransperentViewOnAnotherViewActivity extends Activity {
/** Called when the activity is first created. */
ImageView first, second;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
first = (ImageView) findViewById(R.id.first);
second = (ImageView) findViewById(R.id.second);
second.setAlpha(127);
}
}
</pre>
<br />
<br />
<br />
Description : Using setAlpha() we can Sets the opacity of the view. <a href="http://developer.android.com/reference/android/view/View.html#setAlpha%28float%29" target="_blank">You can get more information from developer site.</a><br />
<br />
Output :<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHXOefEADkvz0DAuecn0FdL6OxU0R1nrB-QxOiOq7tfN48qo5rSZJNkTvtEZBGvH6xuxeOQu_tKPeuVOwMoDj0oxpaWCuDenLSr7WzenHCJW6i9jXqFzRJr7bRW7xRJY-Xtnh135VItaY/s1600/device-2013-04-11-163908.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHXOefEADkvz0DAuecn0FdL6OxU0R1nrB-QxOiOq7tfN48qo5rSZJNkTvtEZBGvH6xuxeOQu_tKPeuVOwMoDj0oxpaWCuDenLSr7WzenHCJW6i9jXqFzRJr7bRW7xRJY-Xtnh135VItaY/s400/device-2013-04-11-163908.png" width="240" /></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-20712786250526062052013-04-11T03:19:00.003-07:002013-04-11T22:45:31.976-07:00How to calculate difference between two dates in android ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<pre class="default prettyprint prettyprinted"><code><span class="kwd">Following is code for get difference between two dates (date1 and date2). </span></code></pre>
<br />
<pre name="code"><pre class="default prettyprint prettyprinted"><code><span class="kwd">long</span><span class="pln"> difference </span><span class="pun">=</span><span class="pln"> date2</span><span class="pun">.</span><span class="pln">getTime</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> date1</span><span class="pun">.</span><span class="pln">getTime</span><span class="pun">();</span><span class="pln">
days </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(</span><span class="pln">difference </span><span class="pun">/</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">24</span><span class="pun">));</span><span class="pln">
hours </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pun">)</span><span class="pln"> </span><span class="pun">((</span><span class="pln">difference </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">24</span><span class="pun">*</span><span class="pln">days</span><span class="pun">))</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">60</span><span class="pun">));</span><span class="pln">
min </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(</span><span class="pln">difference </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">24</span><span class="pun">*</span><span class="pln">days</span><span class="pun">)</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="lit">60</span><span class="pun">*</span><span class="pln">hours</span><span class="pun">))</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1000</span><span class="pun">*</span><span class="lit">60</span><span class="pun">);</span></code></pre>
</pre>
<pre class="default prettyprint prettyprinted"><code><span class="pun"> Visit : <a href="http://stackoverflow.com/a/11219953/1405983" target="_blank">Visit My answer Here</a> </span></code></pre>
<pre class="default prettyprint prettyprinted"><code><span class="pun"><a name='more'></a> </span></code></pre>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-9798703669280686342013-04-11T03:09:00.002-07:002013-04-11T03:29:38.828-07:00How to update price of an application on Google Play Store?<div dir="ltr" style="text-align: left;" trbidi="on">
Now I want to share steps for update price of an application on google play store.<br />
<br />
Suppose you published paid application on google play store, Now you have to update price of an app then following are steps.<br />
<br />
<br />
1. Logging in to your google account<br />
<br />
>> <a href="https://play.google.com/apps/publish" target="_blank">Developer Login </a> <br />
<br />
<br />
2. Selecting your application which you want to update.<br />
<br />
3. Selecting Pricing and Distribution<br />
<br />
4. Changing the current price to new one in the default price section<br />
<br />
5. Clicked on save and update.<br />
<br />
<br />
Now wait for 2 to 3 hours your price will be updated on google play store. </div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-8859123136318224822013-04-03T02:50:00.001-07:002013-04-11T22:49:15.986-07:00How to display image from URL in android ?<div dir="ltr" style="text-align: left;" trbidi="on">
Now we have to explain how to display image from URL. ImageView is used
to display image in android. Here we use AsyncTask for loading image
from URL. Now lets we explain it with Example.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.weebly.com/uploads/1/1/2/9/11298616/8590025_orig.png?0" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://www.weebly.com/uploads/1/1/2/9/11298616/8590025_orig.png?0" width="266" /></a></div>
<br />
<br />
<br />
Above is our final Screen shot display image from URL.<br />
<br />
<br />
Create new Android Project AndroidAdvanceDisplayImageURL. <br />
Layout file main.xml looks like following.<br />
<br />
<br />
<pre name="code"> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" ></pre>
<pre name="code"> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:text />
<ImageView
android:id="@+id/my_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /></pre>
<pre name="code"></LinearLayout>
</pre>
-> Here we take imageview to display image. Now coding part.<br />
<br />
<br />
<span style="font-weight: bold;"> AndroidAdvanceImageLoad.java</span><br />
<br />
<pre name="code"> public class AndroidAdvanceImageLoad extends Activity {
ImageView my_img;
Bitmap mybitmap;
ProgressDialog pd;</pre>
<pre name="code"> @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new DisplayImageFromURL((ImageView) findViewById(R.id.my_image))
.execute("http://www.tmonews.com/wp-content/uploads/2012/10/androidfigure.jpg");
}
private class DisplayImageFromURL extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;</pre>
<pre name="code"> @Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd = new ProgressDialog(AndroidAdvanceImageLoad.this);
pd.setMessage("Loading...");
pd.show();
}
public DisplayImageFromURL(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
pd.dismiss();
}
}
}</pre>
<br />
<br />
-> Here we create DisplayImageFromURL class which loads image from
URL and display it on imageview. It take 2 arguments one is image id and
another is Image URL from which you display image. </div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com6tag:blogger.com,1999:blog-6606063074222360634.post-1699112491824988792013-04-03T02:34:00.000-07:002013-04-11T23:05:24.944-07:00How to create Custom dialog in android ? How it useful for real world programming ?<div dir="ltr" style="text-align: left;" trbidi="on">
Custom dialog created by using your layout file and that file you can
bind your layout to dialog box.And it is useful when we have to
integrate facebook,twitter and all other real word programming.<br />
<br />
<b>Steps To Create Custom Dialog<br />==========================</b><br />
1. Create your layout which is shown in dialog.<br />
2. Bind that layout file to dialog<br />
3. Show your Dialog on any event.<br />
4. Done<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.weebly.com/uploads/1/1/2/9/11298616/6461522_orig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://www.weebly.com/uploads/1/1/2/9/11298616/6461522_orig.png" width="176" /></a><a href="http://www.weebly.com/uploads/1/1/2/9/11298616/257910_orig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://www.weebly.com/uploads/1/1/2/9/11298616/257910_orig.png" width="177" /></a></div>
<br />
<br />
<br />
<h2 class="element editable-text" contenteditable="true" id="123993819541525495" style="text-align: left;">
<span style="font-size: small;">1.Layout
your android custom dialog in xml file. create new project in android
and give name CustomDialog in that layout folder create file login.xml
which is your dialog file and write above code.</span></h2>
<pre name="code"><h2 class="element editable-text" contenteditable="true" id="123993819541525495" style="text-align: left;">
<span style="font-size: small;"><span style="font-weight: normal;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="font-weight: normal;"><LinearLayout xmlns:android="</span><a href="http://schemas.android.com/apk/res/android" style="font-weight: normal;" title="">http://schemas.android.com/apk/res/android</a><span style="font-weight: normal;">"</span>
<span style="font-weight: normal;"> android:layout_width="match_parent" </span>
<span style="font-weight: normal;"> android:layout_height="wrap_content" </span>
<span style="font-weight: normal;"> android:background="#ff00ff" </span>
<span style="font-weight: normal;"> android:orientation="vertical"></span>
<span style="font-weight: normal;"> <TextView </span>
<span style="font-weight: normal;"> android:id="@+id/username_view"</span>
<span style="font-weight: normal;"> android:layout_height="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_width="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_marginLeft="20dip"</span>
<span style="font-weight: normal;"> android:layout_marginRight="20dip"</span>
<span style="font-weight: normal;"> android:text="@string/username"</span>
<span style="font-weight: normal;"> android:gravity="left"</span>
<span style="font-weight: normal;"> android:textAppearance="?android:attr/textAppearanceMedium" </span>
<span style="font-weight: normal;"> /></span>
<span style="font-weight: normal;"> </span>
<span style="font-weight: normal;"> <EditText</span>
<span style="font-weight: normal;"> android:id="@+id/username_edit"</span>
<span style="font-weight: normal;"> android:layout_height="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_width="match_parent"</span>
<span style="font-weight: normal;"> android:layout_marginLeft="20dip"</span>
<span style="font-weight: normal;"> android:layout_marginRight="20dip"</span>
<span style="font-weight: normal;"> android:scrollHorizontally="true"</span>
<span style="font-weight: normal;"> android:autoText="false"</span>
<span style="font-weight: normal;"> android:singleLine="true"</span>
<span style="font-weight: normal;"> android:capitalize="none"</span>
<span style="font-weight: normal;"> android:gravity="fill_horizontal"</span>
<span style="font-weight: normal;"> android:textAppearance="?android:attr/textAppearanceMedium" /></span>
<span style="font-weight: normal;"> <TextView</span>
<span style="font-weight: normal;"> android:id="@+id/password_view"</span>
<span style="font-weight: normal;"> android:layout_height="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_width="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_marginLeft="20dip"</span>
<span style="font-weight: normal;"> android:layout_marginRight="20dip"</span>
<span style="font-weight: normal;"> android:text="@string/password"</span>
<span style="font-weight: normal;"> android:gravity="left"</span>
<span style="font-weight: normal;"> android:textAppearance="?android:attr/textAppearanceMedium" </span>
<span style="font-weight: normal;"> /></span>
<span style="font-weight: normal;"> </span>
<span style="font-weight: normal;"> <EditText </span>
<span style="font-weight: normal;"> android:id="@+id/password_edit"</span>
<span style="font-weight: normal;"> android:layout_height="wrap_content"</span>
<span style="font-weight: normal;"> android:layout_width="match_parent"</span>
<span style="font-weight: normal;"> android:layout_marginLeft="20dip"</span>
<span style="font-weight: normal;"> android:layout_marginRight="20dip"</span>
<span style="font-weight: normal;"> android:scrollHorizontally="true"</span>
<span style="font-weight: normal;"> android:autoText="false"</span>
<span style="font-weight: normal;"> android:singleLine="true"</span>
<span style="font-weight: normal;"> android:capitalize="none"</span>
<span style="font-weight: normal;"> android:gravity="fill_horizontal"</span>
<span style="font-weight: normal;"> android:password="true"</span>
<span style="font-weight: normal;"> android:textAppearance="?android:attr/textAppearanceMedium" </span>
<span style="font-weight: normal;"> /></span>
<span style="font-weight: normal;"> </LinearLayout></span></span><span style="font-size: small;"> </span>
</h2>
</pre>
<h2 class="element editable-text" contenteditable="true" id="507861873853476647" style="text-align: left;">
<span style="font-size: small;">2. Now create your second xml file call first.xml file in layout which is shown after login done</span></h2>
<pre name="code"><h2 class="element editable-text" contenteditable="true" id="507861873853476647" style="text-align: left;">
<span style="font-size: small;"> <span style="font-weight: normal;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="font-weight: normal;"><LinearLayout</span>
<span style="font-weight: normal;"> xmlns:android="</span><a href="http://schemas.android.com/apk/res/android" style="font-weight: normal;" title="">http://schemas.android.com/apk/res/android</a><span style="font-weight: normal;">"</span>
<span style="font-weight: normal;"> android:orientation="vertical"</span>
<span style="font-weight: normal;"> android:layout_width="match_parent"</span>
<span style="font-weight: normal;"> android:layout_height="match_parent" </span>
<span style="font-weight: normal;"> </span>
<span style="font-weight: normal;"> <TextView</span>
<span style="font-weight: normal;"> android:layout_width="wrap_content"</span>
<span style="font-weight: normal;">
android:layout_height="wrap_content" </span>
<span style="font-weight: normal;"> android:text="Welcome to First Page" </span>
<span style="font-weight: normal;"> android:textColor="#00ff00"</span>
<span style="font-weight: normal;"> /></span>
<span style="font-weight: normal;"></LinearLayout></span></span></h2>
<a name='more'></a></pre>
<h2 class="element editable-text" contenteditable="true" id="507861873853476647" style="text-align: left;">
</h2>
<h2 class="element editable-text" contenteditable="true" id="827918865958427838">
<span style="font-size: small;">3.
Now change the code of main.xml file which is available in layout
folder to show your dialog in this layout we have put one button.</span></h2>
<pre name="code"><h2 class="element editable-text" contenteditable="true" id="507861873853476647" style="text-align: left;">
<span style="font-size: small;"><span style="font-weight: normal;"><?xml version="1.0" encoding="utf-8"?></span>
<span style="font-weight: normal;"> <LinearLayout </span>
<span style="font-weight: normal;"> xmlns:android="</span><a href="http://schemas.android.com/apk/res/android" style="font-weight: normal;" title="">http://schemas.android.com/apk/res/android</a><span style="font-weight: normal;">"</span>
<span style="font-weight: normal;"> android:layout_width="fill_parent" </span>
<span style="font-weight: normal;"> android:layout_height="fill_parent" </span>
<span style="font-weight: normal;"> android:gravity="center"</span>
<span style="font-weight: normal;"> android:orientation="vertical"></span>
<span style="font-weight: normal;"> </span>
<span style="font-weight: normal;"> <Button </span>
<span style="font-weight: normal;"> android:id="@+id/button" </span>
<span style="font-weight: normal;"> android:layout_width="wrap_content"</span>
<span style="font-weight: normal;"> android:textColorHint="#00FF00"</span>
<span style="font-weight: normal;"> android:textColor="#FF0000"</span>
<span style="font-weight: normal;"> android:textSize="20px"</span>
<span style="font-weight: normal;"> android:layout_height="wrap_content" </span>
<span style="font-weight: normal;"> android:text="Login"/></span>
<span style="font-weight: normal;"></LinearLayout></span></span><span style="font-size: small;"> <span style="font-weight: normal;"> </span></span></h2>
</pre>
<h2 class="element editable-text" contenteditable="true" id="537561058934094491" style="text-align: left;">
<span style="font-size: small;">4.
Now bind all xml file to java file so look at src folder in your
project and change the CustomDialogActivity.java file. You can loged in
by using same username and password.</span></h2>
<h2 class="element editable-text" contenteditable="true" id="537561058934094491" style="text-align: left;">
<span style="font-size: small;"><span style="font-weight: normal;">package </span><b style="font-weight: normal;">your package name</b><span style="font-weight: normal;">.CustomDialog;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import </span><b style="font-weight: normal;">your package name</b><span style="font-weight: normal;">.CustomDialog.CustomDialogActivity;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import </span><b style="font-weight: normal;">your package name</b><span style="font-weight: normal;">.CustomDialog.R;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.app.Activity;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.app.AlertDialog;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.app.Dialog;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.content.DialogInterface;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.content.Intent;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.os.Bundle;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.view.LayoutInflater;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.view.View;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.view.View.OnClickListener;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.widget.Button;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.widget.EditText;</span><br style="font-weight: normal;" /><span style="font-weight: normal;"></span><br style="font-weight: normal;" /><span style="font-weight: normal;">public class CustomDialogActivity extends Activity </span><br style="font-weight: normal;" /><span style="font-weight: normal;">{</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> private static final int DIALOG_TEXT_ENTRY = 1;</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> protected Dialog onCreateDialog(int id) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> switch (id) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> case DIALOG_TEXT_ENTRY:</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> // This example shows how to add a custom layout to an AlertDialog </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> LayoutInflater factory = LayoutInflater.from(this);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> final View textEntryView = factory.inflate(R.layout.login,null);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> return new AlertDialog.Builder(CustomDialogActivity.this)</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">setIcon(R.drawable.user)</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">setTitle(R.string.txt_entry)</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">setView(textEntryView)</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">setPositiveButton(R.string.Login, new DialogInterface.OnClickListene() </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> public void onClick(DialogInterface dialog, int whichButton); </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> EditText username,password; </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> username=(EditText)textEntryView.findViewById(R.id.username_edit);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> password=(EditText)textEntryView.findViewById(R.id.password_edit);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> if(username.getText().toString.equals(password.getText().toString()))</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> Intent i=new Intent(CustomDialogActivity.this,First.class);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> startActivity(i);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> })</span><br style="font-weight: normal;" /><span style="font-weight: normal;">
</span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> public void onClick(DialogInterface dialog, int whichButton) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> { </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> /* User clicked cancel so do some stuff */</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> })</span><b style="font-weight: normal;">.</b><span style="font-weight: normal;">create(); </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> return null;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">}</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><br style="font-weight: normal;" /><span style="font-weight: normal;">/** Called when the activity is first created. */</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> @Override protected void onCreate(Bundle savedInstanceState) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> super.onCreate(savedInstanceState);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> setContentView(R.layout.main);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> Button textEntry = (Button) findViewById(R.id.button);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> textEntry.setOnClickListener(new OnClickListener() </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> public void onClick(View v) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> showDialog(DIALOG_TEXT_ENTRY);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> });</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> </span></span> <span style="font-size: small;"><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;">}</span></span><span style="font-size: small;"> </span></h2>
<h2 class="element editable-text" contenteditable="true" id="537561058934094491" style="text-align: left;">
<span style="font-size: small;"><br /></span></h2>
<h2 class="element editable-text" contenteditable="true" id="700848395828735384" style="text-align: left;">
<span style="font-size: small;">5. Now Create your second class called First.java file in src folder</span></h2>
<h2 class="element editable-text" contenteditable="true" id="700848395828735384" style="text-align: left;">
<span style="font-size: small;"><span style="font-weight: normal;">package com.ss.paresh.DD;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.app.Activity;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.content.Intent;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">import android.os.Bundle;</span><br style="font-weight: normal;" /><span style="font-weight: normal;">public class First extends Activity</span><br style="font-weight: normal;" /><span style="font-weight: normal;">{</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> protected void onCreate(Bundle savedInstanceState) </span><br style="font-weight: normal;" /><span style="font-weight: normal;"> {</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> super.onCreate(savedInstanceState);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> setContentView(R.layout.first);</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> Intent i=getIntent();</span><br style="font-weight: normal;" /><span style="font-weight: normal;"> }</span><br style="font-weight: normal;" /><span style="font-weight: normal;">}</span></span><span style="font-size: small;"> </span></h2>
<h2 class="element editable-text" contenteditable="true" id="700848395828735384" style="text-align: left;">
<span style="font-size: small;"><br /></span></h2>
<h2 class="element editable-text" contenteditable="true" id="908411845556459095">
<span style="font-size: small;">6.
Important note about this post put one drawable name user.png in your
drawable folder otherwise error occurs in your project now your custom
dialog project is completed run build and go best of luck.</span></h2>
<h2 class="element editable-text" contenteditable="true" id="507861873853476647" style="text-align: left;">
<span style="font-size: small;"><span style="font-weight: normal;"> </span></span><span style="font-size: small;"> </span></h2>
<h2 class="element editable-text" contenteditable="true" id="123993819541525495" style="text-align: left;">
<span style="font-size: small;"> </span></h2>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com1tag:blogger.com,1999:blog-6606063074222360634.post-53901611517246440612013-04-03T02:23:00.005-07:002013-04-03T02:23:58.586-07:00Android project structure<div dir="ltr" style="text-align: left;" trbidi="on">
Create new project "<span style="font-weight: bold;">AndroidAdvanceHelloWorld</span>"in eclipse.<br />After you create a new project in eclipse, you will see the following top-level folders in your project.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.weebly.com/uploads/1/1/2/9/11298616/1175655_orig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://www.weebly.com/uploads/1/1/2/9/11298616/1175655_orig.png" width="201" /></a></div>
<br />
<br />
Let we explain each step by step.<br />
<br />
<br /><br /> <span style="font-weight: bold;">(1) "src" folder</span><br /><br />This
folder will contain the Java source files that you will be creating. In
the screenshot you can see the ‘activity’ files that were created for
the sample project. The files inside this folder will be organized
according to the package structure. This is similar to the /src folder
which is present in any normal Java project. <br /><br />You can have more
than one package in your Android application. Its always a good practice
to break the source code of your application into different packages
based on its core functionality. All the source files of your
Activities, Services etc. Goes into this folder. In the above screen,
you can see the source file of the Activity that we created for our
project.<br />
<br /><br /> <span style="font-weight: bold;">(2) "gen" folder</span><br />The
gen directory in an Android project contains generated values. R.java
is a generated class which contains references to certain resources of
the project.<br /><br />If you create a new resource, the corresponding
reference is automatically created in R.java via the Eclipse ADT tools.
These references are static integer values and define IDs for the
resources.<br /><br />The Android system provides methods to access the corresponding resource via these IDs.<br /><br />For example to access a String with the R.string.yourString ID, you would use the getString(R.string.yourString)) method.<br /><br />R.java
is automatically created by the Eclipse development environment, manual
changes are not necessary and will be overridden by the tooling. <br />
<br /><br /> <span style="font-weight: bold;">(3) "android-version number" </span><br />The
android-version number folder, which will contain the libraries
(jars/android.jar) that are need for the project. In the screenshot,
you can see that it contains the framework jar file. This is similar to
the /lib folder which is present in any normal Java project.<br /><br /><br /> <span style="font-weight: bold;">(4) "res" folder</span><br />This
directory contains all the external resources (images, data files etc)
that are used by the android application. These external resources
(content) will be referenced in the android application.<br /><br /> The "res" folder also contains sub-folders like following.<br /><br /> ->
/res/drawable -- Bitmap files / Nine-Patches
(re-sizable bitmaps) / State lists / Shapes / Animation drawables /
Other drawables <br /> -> /res/layout -- XML files that define a user interface layout. <br /> -> /res/values -- XML files that contain simple values, such as strings, integers, and colors.<br /> <br /> arrays.xml for resource arrays (typed arrays).<br /> colors.xml for color values<br /> dimens.xml for dimension values.<br /> strings.xml for string values.<br /> styles.xml for styles.<br /><br /> ->
/res/drawable-hdpi -- The hdpi qualifier indicates that
the resources in that directory are for devices with a high-density
screen.<br /><br /> -> /res/drawable-ldpi -- The ldpi
qualifier indicates that the resources in that directory are for devices
with a low-density screen.<br /><br /> -> /res/drawable-mdpi
-- The mdpi qualifier indicates that the resources in that directory
are for devices with a medium-density screen.<br /><br /> ->
/res/drawable-xhdpi -- The xhdpi qualifier indicates that the
resources in that directory are for devices with a extra Large-density
screen.<br /><br /> -> /res/anim -- XML files that define tween animations<br /><br /> -> /res/color -- XML files that define a state list of colors. <br /><br /> ->
/res/menu -- XML files that define
application menus, such as an Options Menu, Context Menu, or Sub Menu. <br /><br /> -> /res/raw -- Arbitrary files to save in their raw form. <br /><br /> <span style="font-weight: bold;">(5) "assets" folder</span><br /><br />This
folder also contains external resources used in the application like
the /res folder. But the main difference is that the resources are
stored in raw format and can be read only programmatically.<br /><br /> <span style="font-weight: bold;">(6) AndroidManifest.xml</span><br /><br />The
components and settings of an Android application are described in the
AndroidManifest.xml file. For example all Activities and Services of the
application must be declared in this file. It must also contain the
required permissions for the application.<br /><br />Google Play requires
that every Android application uses its own unique package. Therefore it
is a good habit to use your reverse domain name as package name. This
will avoid collisions with other Android applications. It contains
information about various activities, views, services etc.<br /><br /><span> I hope this tutorial helps you.</span> </div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-24709134228818427942013-04-03T02:20:00.001-07:002013-04-03T02:20:48.112-07:00What is Listview in android and how to work with android Listview ?<div dir="ltr" style="text-align: left;" trbidi="on">
Android provides the ListView class
which is capable of displaying a scrollable list of
items. These items can be of any type.
<br /><br /><span> Now lets take one example of ListView. We can understand ListView step by step.</span> <br /><br /><span> Step 1 :- Create one project give it name ListViewDemo. </span>now in main.xml file we take one ListView like following.<br /><br /><span> <span style="font-weight: bold;">main.xml</span></span><br /><br /><span> </span><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:orientation="vertical" ><br /> <TextView<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_marginLeft="10dp"<br /> android:text="Android Advance Listview Demo"<br /> android:textColor="#ff9966"<br /> android:textSize="20dp"<br /> android:text /><br /> <span style="font-weight: bold;"><ListView</span><br /><span style="font-weight: bold;"> android:id="@+id/listview"</span><br /><span style="font-weight: bold;"> android:layout_width="fill_parent"</span><br /><span style="font-weight: bold;"> android:layout_height="wrap_content" ></span><br /><span style="font-weight: bold;"> </ListView></span><br /></LinearLayout><br /><br /><span> step 2 :- Now we create one java file which items in a list and handle events. </span><br /><br /><span> </span><span style="font-weight: bold;">ListVIewDemoActivity.java </span><br /><br /><span> </span>public class ListVIewDemoActivity extends Activity implements OnClickListener {<br /> ListView listview; <br /> ArrayList<String> listviewitems = new ArrayList<String>(); <br /><span></span><br /><span></span> <span style="font-weight: bold;"> // listviewitems is array which display items in a list</span><br /><span></span><br /><span> </span>@Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /><br /><span> <span style="font-weight: bold;">// Now get id of ListView </span></span><br /> listview = (ListView) findViewById(R.id.listview);<br /> <br /> }<br /><span> </span>@Override<br /> protected void onResume() {<br /> super.onResume();<br /><span> </span><br /><span> <span style="font-weight: bold;">
we need to clear listviewitems every time becase when this activity
resumes it add elements to the list so first clear listview and after we
add elements to listviewitems. </span></span><br /><span></span><br /> listviewitems.clear();<br /> listviewitems.add("Animals");<br /> listviewitems.add("Birds");<br /> listviewitems.add("Fruits");<br /> listviewitems.add("Computer Parts");<br /> listviewitems.add("Electronic Products");<br /><br /><span> </span><span style="font-weight: bold;">A
ListView receives its data via an
adapter. The adapter also defines how each row is the
ListView is displayed. The adapter
is assigned to the list via the
setAdapter method on the
ListView object. </span> <span style="font-weight: bold;">An adapter extend the <a href="http://developer.android.com/reference/android/widget/BaseAdapter.html" title=""> BaseAdapter</a>
class. Android provides several
standard adapters; the most important
are ArrayAdapter and
CursorAdapter. </span> <span style="font-weight: bold;">Here we use BaseAdapter.</span><br /><br /> listview.setAdapter(new ListAdapter(this, this));<br /> }<br /><br /><span> <span style="font-weight: bold;">Now we have to create our own ListAdapter</span></span><span style="font-weight: bold;"> for listview adapter.</span><br /><br /><span> </span>private class ListAdapter extends BaseAdapter {<br /> LayoutInflater inflater;<br /><br /><span> <span style="font-weight: bold;"> we have to create one inner class ViewHolder for storing child views.</span></span><br /> ViewHolder viewHolder;<br /> Activity activity;<br /><br /><br /><span> <span style="font-weight: bold;"> constructor of ListAdapter</span></span><br /><span> </span>public ListAdapter(Context context, Activity act) {<br /> inflater = LayoutInflater.from(context);<br /> this.activity = act;<br /> }<br /><br /><br /><span> <span style="font-weight: bold;">getCount() display total numbers of items in a list</span></span><br /><span> </span>public int getCount() {<br /> return listviewitems.size();<br /> }<br /><br /><span> </span>public Object getItem(int position) {<br /> return position;<br /> }<br /><br /> public long getItemId(int position) {<br /> return position;<br /> }<br /><br /> public View getView(final int position, View convertView,<br /> ViewGroup parent) {<br /> if (convertView == null) {<br /><br /> convertView = inflater.inflate(R.layout.list_row, null);<br /> viewHolder = new ViewHolder();<br /><br /> viewHolder.pname = (TextView) convertView<br /> .findViewById(R.id.txtname);<br /><br /> convertView.setTag(viewHolder);<br /><br /> } else {<br /> viewHolder = (ViewHolder) convertView.getTag();<br /> }<br /><br /> viewHolder.pname.setText(listviewitems.get(position));<br /><br /><span> </span><span style="font-weight: bold;">To
react to selections in the list set an OnItemClickListener to your
ListView. </span><br /><span></span><br /> convertView.setOnClickListener(new OnItemClickListener(position));<br /> return convertView;<br /><br /> }<br /> }<br /> <span style="font-weight: bold;">Within
the getView() method you would inflate an
XML based layout and then set the values
of the individual Views in
the layout. For inflating an XML layout you can use the system
service LayoutInflator. This service can get
accessed via the Activity or via the
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)
method call. </span><br /><br /><span> </span>private class ViewHolder {<br /> TextView pname;<br /> }<br /><br /><span> <span style="font-weight: bold;">Now we create our own listener for the listview item click. </span></span><br /><br /><span></span><span> </span>private class OnItemClickListener implements OnClickListener {<br /> private int mPosition;<br /><br /> OnItemClickListener(int position) {<br /> mPosition = position;<br /> }<br /><br /> public void onClick(View v) {<br /><br /> Toast.makeText(ListVIewDemoActivity.this,<br /> "" + listviewitems.get(mPosition), Toast.LENGTH_LONG)<br /> .show();<br /><br /><span> <span style="font-weight: bold;"> we pass position which is clicked in listview to next activity by passing intent to </span></span><span style="font-weight: bold;">ListItemDetail.java</span>.<br /> Intent i = new Intent(ListVIewDemoActivity.this,<br /> ListItemDetail.class);<br /> i.putExtra("position", "" + mPosition);<br /> startActivity(i);<br /> }<br /><br /> }<br /> step 3 :- we need to create list_row.xml file for list row display so create new xml file like following. <br /><br /><span> </span><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:orientation="vertical" ><br /> <LinearLayout<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:orientation="horizontal" ><br /> <TextView<br /> android:id="@+id/txtname"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_marginLeft="10dp"<br /> android:layout_marginRight="20dp"<br /> android:text="Product Name"<br /> android:textColor="#FF9900"<br /> android:textSize="22dp"<br /> android:text /><br /> </LinearLayout><br /></LinearLayout><br /><span></span><br /><span> Step 4 :- Now for dispay item which is clicked we have to create new class name it to </span>ListItemDetail.java. We display image corresponding to item click on listview so create one xml file which display image.<br /><br /><br /><span> </span><span style="font-weight: bold;">listitemdetail.xml</span><br /><span></span><br /><span> </span><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:orientation="vertical" ><br /> <ImageView<br /> android:id="@+id/imageview"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent" /><br /></LinearLayout><br /><br /><span> </span><span style="font-weight: bold;">ListItemDetail.java</span><br /><span> </span>public class ListItemDetail extends Activity {<br /> <br /><span> <span style="font-weight: bold;">we get position and store it to variable</span></span>. <br /><span> </span>int position;<br /><span> </span> ImageView image;<br /><span> </span><br /> int[] images = { R.drawable.animals, R.drawable.birds, R.drawable.fruits,<br /> R.drawable.pcparts, R.drawable.electronics };<br /><span></span><br /> @Override<br /> protected void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.listitemdetail);<br /> Bundle extras = getIntent().getExtras();<br /> if (extras != null) {<br /><br /><span style="font-weight: bold;">
now get position which is passed from first activity. Here we pass from
first activity using putExtra() so we must covert it in integer by
using Integer.valueOf() method by using following. </span><br /><span></span><br /> position = Integer.valueOf(extras.getString("position"));<br /> image = (ImageView) findViewById(R.id.imageview);<br /><br /><span> <span style="font-weight: bold;"> We set image on imageview by using </span></span><span style="font-weight: bold;">setBackgroundResource() method.</span><br /> image.setBackgroundResource(images[position]);<br /> }<br /> }<br />}<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.weebly.com/uploads/1/1/2/9/11298616/1173520.png?352" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="Http://www.weebly.com/uploads/1/1/2/9/11298616/1173520.png?352" width="192" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.weebly.com/uploads/1/1/2/9/11298616/7951924.png?350" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://www.weebly.com/uploads/1/1/2/9/11298616/7951924.png?350" width="191" /></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-43152270110854591242013-04-03T02:11:00.000-07:002013-04-03T02:11:33.336-07:00How to send SMS in android ?<div dir="ltr" style="text-align: left;" trbidi="on">
In android you can send SMS by using <a href="http://developer.android.com/reference/android/telephony/gsm/SmsManager.html" title="">SmsManager</a> API. Now we have to describe how send SMS in android pragmatically. <br /><br /><span> </span><span style="font-weight: bold;">step
1 :- Create new project give name it to SendSMSDemo. Now we need two
TextViews (one for enter phone number and one for message) and one
Button for handling event of sending SMS. Your xml looks like this.</span><br /><br /> <span style="font-weight: bold;">main.xml</span><br /><br /><?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:orientation="vertical" ><br /><br /> <TextView<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:gravity="center"<br /> android:text="Android Advance SEND SMS "<br /> android:textSize="23dp" /><br /><br /> <LinearLayout<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="15dp"<br /> android:orientation="vertical" ><br /><br /> <TextView<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:text="Enter Phone Number"<br /> android:textSize="16dp"<br /> android:text /><br /><br /> <EditText<br /> android:id="@+id/txtnumbers"<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="5dp"<br /> android:input /><br /> </LinearLayout><br /><br /> <LinearLayout<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="15dp"<br /> android:orientation="vertical" ><br /><br /> <TextView<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:text="Enter Your Message"<br /> android:textSize="16dp"<br /> android:text /><br /><br /> <EditText<br /> android:id="@+id/txtnotes"<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="5dp" /><br /> </LinearLayout><br /><br /> <Button<br /> android:id="@+id/btnsend"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_gravity="center"<br /> android:gravity="center"<br /> android:text="Send Message" /><br /><br /></LinearLayout><br /><br /> <span style="font-weight: bold;">
Step 2 :- Now corresponding to this you need to handle event of send
SMS. Now when button clicked we have to check phone number field is
empty or not. If Phone Number field is empty then we display Toast
message to user that enter phone number. </span><br /><br /><br /> <span style="font-weight: bold;">SendSMSDemoActivity.java</span><br /><br />package com.androidadvance.screen;<br /><br />import android.app.Activity;<br />import android.os.Bundle;<br />import android.telephony.SmsManager;<br />import android.view.View;<br />import android.view.View.OnClickListener;<br />import android.widget.Button;<br />import android.widget.EditText;<br />import android.widget.Toast;<br /><br />public class SendSMSDemoActivity extends Activity implements OnClickListener {<br /> EditText txtnotes, txtnumber;<br /> Button btnsend;<br /><br /> /** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /><br /> txtnotes = (EditText) findViewById(R.id.txtnotes);<br /> txtnumber = (EditText) findViewById(R.id.txtnumbers);<br /><br /> btnsend = (Button) findViewById(R.id.btnsend);<br /> btnsend.setOnClickListener(this);<br /> }<br /><br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> switch (v.getId()) {<br /> case R.id.btnsend:<br /><br /> Here we have to check for input.<br /><br /> if (txtnumber.getText().toString().equals(""))<br /> Toast.makeText(SendSMSDemoActivity.this,<br /> "Please enter number..", Toast.LENGTH_LONG).show();<br /> else {<br /> try {<br /><br /> <span style="font-weight: bold;">Manages
SMS operations such as sending data, text, and pdu SMS messages. Get
this object by calling the static method SmsManager.getDefault(). </span><br /><br /> SmsManager smsManager = SmsManager.getDefault();<br /> smsManager.sendTextMessage(txtnumber.getText().toString()<br /> .trim(), null, txtnotes.getText().toString(), null,<br /> null);<br /> Toast.makeText(getApplicationContext(), "SMS Sent!",<br /> Toast.LENGTH_LONG).show();<br /> } catch (Exception e) {<br /> Toast.makeText(getApplicationContext(),<br /> "SMS faild, please try again later!",<br /> Toast.LENGTH_LONG).show();<br /> e.printStackTrace();<br /> }<br /> }<br /> break;<br /><br /> default:<br /> break;<br /> }<br /> }<br />}<br /><br /> <span style="font-weight: bold;">Also not forget to give permission in AndroidManifest.xml</span><br /><br /> <uses-permission android:name="<span style="font-weight: bold;">android.permission.SEND_SMS</span>" /><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLE4L37af8elkrgvxCEskvxe2aFruXmmuSEpKUK8gLZAvW_khZkXEk4gekWnv3uY7NrFCbzO70hPGUbRAM3HVAxYJcNiLcDVnaooflMxocxC4-wh5G5NE_o1fgufz04vzclkPKvEBcBaI/s1600/sendsms.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLE4L37af8elkrgvxCEskvxe2aFruXmmuSEpKUK8gLZAvW_khZkXEk4gekWnv3uY7NrFCbzO70hPGUbRAM3HVAxYJcNiLcDVnaooflMxocxC4-wh5G5NE_o1fgufz04vzclkPKvEBcBaI/s320/sendsms.png" width="192" /></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com1tag:blogger.com,1999:blog-6606063074222360634.post-36961761573136423242013-04-03T02:06:00.002-07:002013-04-03T02:06:27.998-07:00What is Intent in android ? How to pass data using Intent ?<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;">In android to pass data between activity Intent is used.
You can use Intent.putExtras() in sender activity and
Intent.getExtras() in receiving activity.</span><br />
<br /><br /><span> Following Example explain intent in android.</span><br />
<br /><br /><span> For this example we create two xml files main.xml and </span>receiver.xml and we create two corresponding java files AndroidIntentExampleActivity.java and ReceiverActivity.java.<br /><br /><span> Following are step by step explanation for this.</span><br />
<br />
<br /><br /><b><span> step 1 :- Create main.xml file. we create two TextView and one EditText and one Button.</span><br /><span></span></b><br /><span> </span><?xml version="1.0" encoding="utf-8"?><br /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:orientation="vertical" ><br /><br /> <TextView<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="20dp"<br /> android:gravity="center"<br /> android:text="@string/hello" /><br /><br /> <TextView<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="10dp"<br /> android:text="@string/enterdata"<br /> android:text /><br /><br /> <EditText<br /> android:id="@+id/enteryourdata"<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="5dp"<br /> android:hint="Enter data"<br /> android:padding="5dp" /><br /><br /> <Button<br /> android:id="@+id/btnok"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_gravity="right"<br /> android:layout_marginRight="15dp"<br /> android:text="Next" /><br /><br /></LinearLayout><br />
<br />
<br />
<br />
<br />
<br /><span> <b>step 2 :- </b></span><b><span>Now corresponding to main.xml create one java file </span>AndroidIntentExampleActivity.java which handles events.</b><br /><br /><span> </span>public class AndroidIntentExampleActivity extends Activity implements<br /> OnClickListener {<br /><br /> EditText txtdata;<br /> Button btnok;<br /> String datatopass;<br /><br /> /** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /><br /> txtdata = (EditText) findViewById(R.id.enteryourdata);<br /> btnok = (Button) findViewById(R.id.btnok);<br /> datatopass = txtdata.getText().toString();<br /> btnok.setOnClickListener(this);<br /><br /> }<br /><br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> Intent intent = new Intent(AndroidIntentExampleActivity.this,ReceiverActivity.class);<br /> Bundle b = new Bundle();<br /> b.putString("data", txtdata.getText().toString());<br /> intent.putExtras(b);<br /> startActivity(intent);<br /><br /> }<br />}<br />
<br />
<br /><span> <b>Step 3 :- Now for receive data you need to create one xml file and one Java file.</b></span><b> First create one xml file receiver.xml which display data passed from first activity.</b><br /><br /> <span style="font-weight: bold;">receiver.xml</span><br /><span></span><br /><span> </span><?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> android:background="@android:color/white"<br /> android:orientation="vertical" ><br /><br /> <TextView<br /> android:id="@+id/displaytext"<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:text="Text" android:gravity="center"<br /> android:textColor="@android:color/black"<br /> android:textSize="20dp"<br /> android:text /><br /><br /></LinearLayout><br /><span> </span><br /><span></span>
Here TextView display the text which is passed from first activity. Now
for handling events create java file ReceiverActivity.java<br />
<br />
<br /><span></span><br /><b><span> step 4 :- Create </span>ReceiverActivity.java </b><br /><br />public class ReceiverActivity extends Activity {<br /> TextView txtdata;<br /> String value;<br /><br /> @Override<br /> protected void onCreate(Bundle savedInstanceState) {<br /> // TODO Auto-generated method stub<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.receiver);<br /> txtdata = (TextView) findViewById(R.id.displaytext);<br /> Bundle extras = getIntent().getExtras();<br /> if (extras != null) {<br /> value = String.valueOf(extras.getString("data"));<br /> Toast.makeText(ReceiverActivity.this, "" + value, Toast.LENGTH_LONG)<br /> .show();<br /> txtdata.setText(value);<br /> }<br /> }<br />}</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-52947457439949085942013-04-02T02:53:00.004-07:002013-09-23T10:14:52.793-07:00Android SQLite Tutorial
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
=> Just like iOS android have in build sqlite database. In this
tutorial, you learn how SQLite databases are designed and manipulated.<br />
<br />
=>
SQLite is a lightweight relational database engine. Instead of the
heavyweight server-based databases, each SQLite database is stored
within a single file on disk. <br />
<br />
=> Android applications can choose to store private application data in a SQLite database. <br />
<br />
=> In SQLite data are stored in table format. A table has columns
with different data types. Each row in a table represents a data
record. <br />
<br />
=> Lets take one example, Let’s say we have a product database with a table called Products. <br />
<br />
<br />
=>The Products table might have 3 typed columns: <br />
<br />
1) ProductID (number)<br />
2) ProductName (string)<br />
3) Pproductprice (string)<br />
<br />
=> We could then add a record to the data base for an Product named computer. <br />
=> We can do following operation on Products table :<br />
<br />
1) ADD (INSERT query)<br />
2) MODIFIED (UPDATE query)<br />
3) DELETE (DELETE query) <br />
<br />
=> Now we perform create, modify and delete operation with Products table.<br />
<br />
<br />
<b> (1) Create table</b><br />
<br />
<br />
CREATE TABLE Products (id INTEGER PRIMARY KEY AUTOINCREMENT, <br />
Productname TEXT NOT NULL, Productprice TEXT NOT NULL );<br />
<br />
<br />
<br />
<b>(2) INSERT into table </b> <br />
<br />
<br />
INSERT into Products(Productname, Productprice)<br />
VALUES('Computer', '50000'); <br />
<br />
<b> (3) UPDATE table</b><br />
<br />
<br />
SQLiteDatabase db;<br />
db.update("Products", values, whereClause, whereArgs);<br />
<br />
<br />
<br />
Now we explain with example. We have to achieve following.<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg83WbH2A_4uaPc1C21tWtWZk1c_ks5WcNxjru0XDOs4cyvLSbTOJ4LzLc73wpXSyH0dxZtT52mwIpHKOBECLJMLcnQvZbUGDj06GQHFEIoGD8ITMvZ4RwzSRyYFZH0Y2psrYn6BvjeCLE/s1600/sendsms.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg83WbH2A_4uaPc1C21tWtWZk1c_ks5WcNxjru0XDOs4cyvLSbTOJ4LzLc73wpXSyH0dxZtT52mwIpHKOBECLJMLcnQvZbUGDj06GQHFEIoGD8ITMvZ4RwzSRyYFZH0Y2psrYn6BvjeCLE/s320/sendsms.png" width="192" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoxXDFS5DHkOXw8o9bRHVkH_jM2dPpJJA4mg_S2d33UxPezC96oioK01zqDrx88fA7O-OV-GUd3QeGQy4Z5sQdCgad1OZQkcIoktdPcXnNkvu-d7IbbF5U3P-YVSljlGRUqHcOVgLOzWU/s1600/device-2013-08-16-151330.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoxXDFS5DHkOXw8o9bRHVkH_jM2dPpJJA4mg_S2d33UxPezC96oioK01zqDrx88fA7O-OV-GUd3QeGQy4Z5sQdCgad1OZQkcIoktdPcXnNkvu-d7IbbF5U3P-YVSljlGRUqHcOVgLOzWU/s320/device-2013-08-16-151330.png" width="192" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn1AH0lqUtTN8ASBf85uCSIuQOt9ZPRH7te1oaiVCgiaE08SEMX0FUGfDx8JHhmrzSOYy-ZwkW9Bk_sSfA9Be0ETTxhFYsWvEUhFQktN5y6D6v3O3YCQf3fMDb9ef9s-0esY60b7RZ_TM/s1600/device-2013-08-16-151801.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn1AH0lqUtTN8ASBf85uCSIuQOt9ZPRH7te1oaiVCgiaE08SEMX0FUGfDx8JHhmrzSOYy-ZwkW9Bk_sSfA9Be0ETTxhFYsWvEUhFQktN5y6D6v3O3YCQf3fMDb9ef9s-0esY60b7RZ_TM/s320/device-2013-08-16-151801.png" width="192" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ-IRL2KLVIQSSQmfLtVbyvOAmEQbzSR8rCUgDHyb7EreEa0dn9tt2xGfqXQ1RHWe9jL4OY2CDx_gWQyyamAENA1Uq4cO7UR7HHvtdSXya3_s2G5NsUPfnXrUSnaO3MaSUA7hvyUZ8WcM/s1600/device-2013-08-16-151841.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ-IRL2KLVIQSSQmfLtVbyvOAmEQbzSR8rCUgDHyb7EreEa0dn9tt2xGfqXQ1RHWe9jL4OY2CDx_gWQyyamAENA1Uq4cO7UR7HHvtdSXya3_s2G5NsUPfnXrUSnaO3MaSUA7hvyUZ8WcM/s320/device-2013-08-16-151841.png" width="192" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp7tC8xELkyGt7WlZqFS5iW1tB-sCow8GJYx0z1BCBiFLOmgmFcsuEo0ZFtDhLwfWOzKbMbdDm7jnW7YPVGgblsYnjMJCbhN0PAz3pPFkpJm_3r8cYeaa7fX4DNViScep3Ax9Sqn0AggA/s1600/device-2013-08-16-151859.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp7tC8xELkyGt7WlZqFS5iW1tB-sCow8GJYx0z1BCBiFLOmgmFcsuEo0ZFtDhLwfWOzKbMbdDm7jnW7YPVGgblsYnjMJCbhN0PAz3pPFkpJm_3r8cYeaa7fX4DNViScep3Ax9Sqn0AggA/s320/device-2013-08-16-151859.png" width="192" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<br />
<br />
<br />
- create new android project <b>AndroidAdvanceSqlite</b>. <br />
<br />
<br />
- create class
<b>AndroidAdvanceSqliteActivity.java</b>, this class describe two options add
record and view record from sqlite database. For this we have to
create main.xml like following.<br />
<br />
<br />
<b> main.xml</b><br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:orientation="vertical" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:gravity="center"<br />
android:text="Android Advance SQLite Tutorial"<br />
android:textSize="18dp"<br />
android:text /><br />
<br />
<Button<br />
android:id="@+id/btn_add"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:text="Add Products"<br />
android:text /><br />
<br />
<Button<br />
android:id="@+id/btn_view"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:text="View Products"<br />
android:text /><br />
<br />
<Button<br />
android:id="@+id/btn_contact"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:onClick="contactMe"<br />
android:text="Contact me for query"<br />
android:textStyle="bold" /> <br />
<br />
</LinearLayout><br />
<br />
<br />
<br />
<br />
- We have to create two buttons for database operation.<br />
<br />
<b>AndroidAdvanceSqliteActivity.java</b><br />
<br />
<br />
public class AndroidAdvanceSqliteActivity extends Activity implements<br />
OnClickListener {<br />
<br />
private Button btn_add, btn_view, btn_search;<br />
<br />
/** Called when the activity is first created. */<br />
@Override<br />
public void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.main);<br />
btn_add = (Button) findViewById(R.id.btn_add);<br />
btn_view = (Button) findViewById(R.id.btn_view);<br />
btn_search = (Button) findViewById(R.id.btn_search);<br />
btn_search.setOnClickListener(this); <br />
btn_add.setOnClickListener(this);<br />
btn_view.setOnClickListener(this);<br />
<br />
}<br />
<br />
@Override<br />
public void onClick(View v) {<br />
// TODO Auto-generated method stub<br />
switch (v.getId()) {<br />
case R.id.btn_add:<br />
Intent addintent = new Intent(AndroidAdvanceSqliteActivity.this,<br />
AddRecord.class);<br />
startActivity(addintent);<br />
break;<br />
<br />
case R.id.btn_view:<br />
Intent viewintent = new Intent(AndroidAdvanceSqliteActivity.this,<br />
ViewRecord.class);<br />
startActivity(viewintent);<br />
break;<br />
<br />
case R.id.btn_search:<br />
Intent searchintent = new Intent(AndroidAdvanceSqliteActivity.this,<br />
SearchProduct.class);<br />
startActivity(searchintent); <br />
break;<br />
default:<br />
break;<br />
}<br />
<br />
}<br />
<br />
public void contactMe(View v) {<br />
<br />
final Intent emailIntent = new Intent(<br />
android.content.Intent.ACTION_SEND);<br />
emailIntent.setType("plain/text");<br />
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,<br />
new String[] { "androiddevelopmentworld@gmail.com" });<br />
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,<br />
"Android sqlite tutorial");<br />
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,<br />
"Android sqlite tutorial contact Me");<br />
startActivity(Intent.createChooser(emailIntent, "Send mail..."));<br />
<br />
} <br />
}<br />
<b><br /></b>
<b><br /></b>
<b><br /></b>
- We are passing intents to AddRecord.java and ViewRecord.java classes
for operation. Now first we have to create AddRecord.java class and
for that we have to create xml file as following.<br />
<br />
<br />
-create new <b>addrecord.xml</b> file<br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:orientation="vertical" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:gravity="center"<br />
android:text="ADD Record"<br />
android:textSize="18dp"<br />
android:text /><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginLeft="5dp"<br />
android:text="Product ID" /><br />
<br />
<EditText<br />
android:id="@+id/txtpid"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:hint="product ID" /><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginLeft="5dp"<br />
android:text="Enter Product Name" /><br />
<br />
<EditText<br />
android:id="@+id/txtpname"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:hint="product name" /><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginLeft="5dp"<br />
android:text="Enter Product Price" /><br />
<br />
<EditText<br />
android:id="@+id/txtpprice"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:hint="product price" /><br />
<br />
<Button<br />
android:id="@+id/btn_addrecord"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_gravity="center"<br />
android:text="Save" /><br />
<br />
</LinearLayout><br />
<br />
<br />
- Now we have to create AddRecord.java like following. When user
click on save button we need to add that record in our database for
that we have to fire query which add record in our database.<br />
<br />
<br />
public class AddRecord extends Activity implements OnClickListener {<br />
<br />
private Button btn_addrecord;<br />
private EditText txtpname, txtpprice, txtpid;<br />
DatabaseHelper db;<br />
ProductModel pm;<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
// TODO Auto-generated method stub<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.addrecord);<br />
<br />
txtpname = (EditText) findViewById(R.id.txtpname);<br />
txtpprice = (EditText) findViewById(R.id.txtpprice);<br />
btn_addrecord = (Button) findViewById(R.id.btn_addrecord);<br />
<br />
txtpid = (EditText) findViewById(R.id.txtpid);<br />
btn_addrecord.setOnClickListener(this);<br />
<br />
}<br />
<br />
@Override<br />
public void onClick(View v) {<br />
// TODO Auto-generated method stub<br />
switch (v.getId()) {<br />
case R.id.btn_addrecord:<br />
<br />
if (txtpname.getText().toString().equals("")<br />
|| txtpprice.getText().toString().equals("")) {<br />
Toast.makeText(AddRecord.this, "Please add values..",<br />
Toast.LENGTH_LONG).show();<br />
} else {<br />
<br />
db = new DatabaseHelper(getApplicationContext());<br />
db.getWritableDatabase();<br />
pm = new ProductModel();<br />
pm.idno = (txtpid.getText().toString());<br />
pm.productname = txtpname.getText().toString();<br />
pm.productprice = txtpprice.getText().toString();<br />
<br />
Log.i("idno,productname,productprice", "" + pm.idno + ""<br />
+ pm.productname + "" + pm.productprice);<br />
db.addProduct(pm);<br />
Toast.makeText(AddRecord.this, "Record Added successfully.",<br />
Toast.LENGTH_LONG).show();<br />
finish(); <br />
}<br />
break;<br />
<br />
default:<br />
break;<br />
}<br />
<br />
}<br />
}<br />
<br />
<br />
- Here we add record using db.addProduct() method. Which we have to create in our DatabaseHelper.java class.<br />
<br />
- our <b>DatabaseHelper.java</b> looks like..<br />
<br />
<br />
public class DatabaseHelper extends SQLiteOpenHelper {<br />
<br />
public static String DATABASENAME = "androidadvancesqlite"; // our database Name<br />
<br />
public static String PRODUCTTABLE = "products"; //table name<br />
<br />
private ArrayList<ProductModel> cartList = new ArrayList<ProductModel>();<br />
Context c;<br />
<br />
<br />
//constructor <br />
public DatabaseHelper(Context context) {<br />
super(context, DATABASENAME, null, 33);<br />
c = context;<br />
}<br />
<br />
@Override<br />
public void onCreate(SQLiteDatabase db) {<br />
db.execSQL("CREATE TABLE if not exists producttable(id INTEGER PRIMARY KEY AUTOINCREMENT,"<br />
+ "productidno"<br />
+ " TEXT ,"<br />
+ "productname"<br />
+ " TEXT,"<br />
+ "productprice" + " TEXT)");<br />
}<br />
<br />
@Override<br />
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {<br />
db.execSQL("DROP TABLE IF EXISTS" + PRODUCTTABLE);<br />
onCreate(db);<br />
}<br />
<br />
//Add record<br />
public void addProduct(ProductModel productitem) {<br />
SQLiteDatabase db = this.getWritableDatabase();<br />
ContentValues contentValues = new ContentValues();<br />
contentValues.put("productidno", productitem.idno);<br />
contentValues.put("productname", productitem.productname);<br />
contentValues.put("productprice", productitem.productprice);<br />
db.insert("producttable", null, contentValues);<br />
db.close();<br />
}<br />
<br />
//update record<br />
public void updateProduct(ProductModel productList) {<br />
SQLiteDatabase db = this.getWritableDatabase();<br />
ContentValues contentValues = new ContentValues();<br />
contentValues.put("productname", productList.productname);<br />
<br />
contentValues.put("productprice", productList.productprice);<br />
db.update("producttable", contentValues, "productidno="<br />
+ productList.idno, null);<br />
db.close();<br />
}<br />
<br />
// delete entire data from table<br />
public void emptyProduct() {<br />
try {<br />
SQLiteDatabase db = this.getWritableDatabase();<br />
db.execSQL("delete from producttable");<br />
db.close();<br />
} catch (Exception e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
// remove specific record from table<br />
public void removeProduct(String productid, String pname, String pprice) {<br />
try {<br />
String[] args = { productid };<br />
getWritableDatabase().delete("producttable", "productidno=?", args);<br />
<br />
} catch (Exception e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
// get all products from database<br />
public ArrayList<ProductModel> getProudcts() {<br />
<br />
cartList.clear();<br />
<br />
SQLiteDatabase db = this.getWritableDatabase();<br />
Cursor cursor = db.rawQuery("select * from producttable", null);<br />
if (cursor.getCount() != 0) {<br />
if (cursor.moveToFirst()) {<br />
do {<br />
ProductModel item = new ProductModel();<br />
<br />
item.idno = cursor.getString(cursor<br />
.getColumnIndex("productidno"));<br />
<br />
item.productname = cursor.getString(cursor<br />
.getColumnIndex("productname"));<br />
<br />
item.productprice = cursor.getString(cursor<br />
.getColumnIndex("productprice"));<br />
<br />
cartList.add(item);<br />
<br />
} while (cursor.moveToNext());<br />
}<br />
}<br />
cursor.close();<br />
db.close();<br />
return cartList;<br />
}<br />
<br />
<br />
public ArrayList<ProductModel> getProudcts(String record) {<br />
<br />
cartList.clear();<br />
<br />
SQLiteDatabase db = this.getWritableDatabase();<br />
Cursor cursor = db.query(true, "producttable", new String[] {<br />
"productidno", "productname", "productprice" }, "productname"<br />
+ "=?", new String[] { record }, null, null, null, null);<br />
<br />
if (cursor.getCount() != 0) {<br />
if (cursor.moveToFirst()) {<br />
do {<br />
ProductModel item = new ProductModel();<br />
<br />
item.idno = cursor.getString(cursor<br />
.getColumnIndex("productidno"));<br />
<br />
item.productname = cursor.getString(cursor<br />
.getColumnIndex("productname"));<br />
<br />
item.productprice = cursor.getString(cursor<br />
.getColumnIndex("productprice"));<br />
<br />
cartList.add(item);<br />
<br />
} while (cursor.moveToNext());<br />
}<br />
}<br />
cursor.close();<br />
db.close();<br />
return cartList;<br />
} <br />
}<br />
<br />
<br />
<br />
- Here we have to specify ProductModel class which is our POJO(Plain
Old Java Object) which will help us to populate all values.<br />
<br />
<br />
<br />
<br />
-
Create new class ProductModel.java which looks like following. It have
three variables idno,productname,productprice and also we have to
declare setter and getter methods for that.<br />
<br />
<b>ProductModel.java</b><br />
<br />
public class ProductModel {<br />
<br />
public String idno="", productname="", productprice="";<br />
<br />
public String getProductname() {<br />
return productname;<br />
}<br />
<br />
public void setProductname(String productname) {<br />
this.productname = productname;<br />
}<br />
<br />
public String getProductprice() {<br />
return productprice;<br />
}<br />
<br />
public void setProductprice(String productprice) {<br />
this.productprice = productprice;<br />
}<br />
<br />
<br />
<br />
public String getIdno() {<br />
return idno;<br />
}<br />
<br />
public void setIdno(String idno) {<br />
this.idno = idno;<br />
}<br />
<br />
}<br />
<b> </b><br />
<b> </b><br />
- Now for delete,update and view records from products table we have
to create new class ViewRecord.java. Here we desplay all records from
database table and delete or update specific record from list.<br />
<br />
<br />
- create new <b>viewrecord.xml</b> file. We display all records in a listview.<br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:orientation="vertical" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:gravity="center"<br />
android:text="View Record"<br />
android:textSize="18dp"<br />
android:text /><br />
<br />
<TextView<br />
android:id="@+id/totalrecords"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:gravity="center"<br />
android:textSize="18dp"<br />
android:text /><br />
<br />
<ListView<br />
android:id="@+id/listview"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content" ><br />
</ListView><br />
<br />
</LinearLayout><br />
<br />
<br />
- Now for handling events and display data we have to create ViewRecord.java like following.<br />
<br />
<br />
<b>ViewRecord.java</b> <br />
<br />
public class ViewRecord extends Activity {<br />
<br />
private ListView listview;<br />
TextView totalrecords;<br />
DatabaseHelper db;<br />
public ArrayList<ProductModel> _productlist = new ArrayList<ProductModel>();<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
// TODO Auto-generated method stub<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.viewrecord);<br />
totalrecords = (TextView) findViewById(R.id.totalrecords);<br />
listview = (ListView) findViewById(R.id.listview);<br />
}<br />
<br />
@Override<br />
protected void onResume() {<br />
// TODO Auto-generated method stub<br />
super.onResume();<br />
<br />
_productlist.clear();<br />
<br />
db = new DatabaseHelper(getApplicationContext());<br />
db.getWritableDatabase();<br />
ArrayList<ProductModel> product_list = db.getProudcts();<br />
<br />
for (int i = 0; i < product_list.size(); i++) {<br />
<br />
String tidno = product_list.get(i).getIdno();<br />
<br />
String tname = product_list.get(i).getProductname();<br />
String tprice = product_list.get(i).getProductprice();<br />
<br />
ProductModel _ProductModel = new ProductModel();<br />
<br />
_ProductModel.setIdno(tidno);<br />
_ProductModel.setProductname(tname);<br />
_ProductModel.setProductprice(tprice);<br />
<br />
_productlist.add(_ProductModel);<br />
}<br />
totalrecords.setText("Total Records :-" + _productlist.size());<br />
listview.setAdapter(new ListAdapter(this));<br />
db.close();<br />
<br />
}<br />
<br />
private class ListAdapter extends BaseAdapter {<br />
LayoutInflater inflater;<br />
ViewHolder viewHolder;<br />
<br />
public ListAdapter(Context context) {<br />
// TODO Auto-generated constructor stub<br />
inflater = LayoutInflater.from(context);<br />
}<br />
<br />
@Override<br />
public int getCount() {<br />
// TODO Auto-generated method stub<br />
return _productlist.size();<br />
}<br />
<br />
@Override<br />
public Object getItem(int position) {<br />
// TODO Auto-generated method stub<br />
return position;<br />
}<br />
<br />
@Override<br />
public long getItemId(int position) {<br />
// TODO Auto-generated method stub<br />
return position;<br />
}<br />
<br />
@Override<br />
public View getView(int position, View convertView, ViewGroup parent) {<br />
// TODO Auto-generated method stub<br />
if (convertView == null) {<br />
<br />
convertView = inflater.inflate(R.layout.listview_row, null);<br />
viewHolder = new ViewHolder();<br />
<br />
viewHolder.txt_pname = (TextView) convertView<br />
.findViewById(R.id.txtdisplaypname);<br />
viewHolder.txt_pprice = (TextView) convertView<br />
.findViewById(R.id.txtdisplaypprice);<br />
<br />
viewHolder.txtidno = (TextView) convertView<br />
.findViewById(R.id.txtdisplaypid);<br />
convertView.setTag(viewHolder);<br />
<br />
} else {<br />
viewHolder = (ViewHolder) convertView.getTag();<br />
}<br />
<br />
viewHolder.txt_pname.setText(_productlist.get(position)<br />
.getProductname().trim());<br />
viewHolder.txt_pprice.setText(_productlist.get(position)<br />
.getProductprice().trim());<br />
<br />
viewHolder.txtidno.setText(_productlist.get(position).getIdno()<br />
.trim());<br />
<br />
final int temp = position;<br />
(convertView.findViewById(R.id.btn_update))<br />
.setOnClickListener(new OnClickListener() {<br />
<br />
public void onClick(View arg0) {<br />
<br />
String _productid = String.valueOf(_productlist<br />
.get(temp).getIdno());<br />
String _productname = _productlist.get(temp)<br />
.getProductname();<br />
String _productprice = _productlist.get(temp)<br />
.getProductprice();<br />
<br />
Intent intent = new Intent(ViewRecord.this,<br />
AddUpdateValues.class);<br />
<br />
Bundle bundle = new Bundle();<br />
bundle.putString("id", _productid);<br />
bundle.putString("name", _productname);<br />
bundle.putString("price", _productprice);<br />
intent.putExtras(bundle);<br />
startActivity(intent);<br />
<br />
}<br />
});<br />
<br />
<br />
<br />
- for delete record we no need to create class we just call removeProduct() method of DatabaseHelper like following. <br />
<br />
<br />
<br />
(convertView.findViewById(R.id.btn_delete))<br />
.setOnClickListener(new OnClickListener() {<br />
<br />
public void onClick(View arg0) {<br />
<br />
AlertDialog.Builder alertbox = new AlertDialog.Builder(<br />
ViewRecord.this);<br />
alertbox.setCancelable(true);<br />
alertbox.setMessage("Are you sure you want to delete ?");<br />
alertbox.setPositiveButton("Yes",<br />
new DialogInterface.OnClickListener() {<br />
<br />
public void onClick(<br />
DialogInterface arg0, int arg1) {<br />
<br />
db.removeProduct(<br />
_productlist.get(temp)<br />
.getIdno().trim(),<br />
"", "");<br />
<br />
ViewRecord.this.onResume();<br />
<br />
Toast.makeText(<br />
getApplicationContext(),<br />
"Record Deleted...",<br />
Toast.LENGTH_SHORT).show();<br />
<br />
}<br />
<br />
});<br />
alertbox.setNegativeButton("No",<br />
new DialogInterface.OnClickListener() {<br />
public void onClick(<br />
DialogInterface arg0, int arg1) {<br />
<br />
}<br />
});<br />
alertbox.show();<br />
}<br />
});<br />
return convertView;<br />
<br />
}<br />
}<br />
<br />
private class ViewHolder {<br />
TextView txt_pname;<br />
TextView txt_pprice;<br />
TextView txtidno;<br />
<br />
}<br />
<br />
} <br />
<br />
<br />
- Here we have to give two buttons with each record in a list that is
update and delete. When user click on Update button we have to pass
intent to new activity that is AddUpdateValues.java and we have to also
pass id,product name and product price of perticular record using
Bundle. <br />
<br />
<br />
<br />
- For update record we create AddUpdateValues.java class. Which will update your record.<br />
<br />
<br />
- create new <b>addupdatevalues.xml</b> file.<br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:orientation="vertical" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginLeft="5dp"<br />
android:text="Enter Product Name" /><br />
<br />
<EditText<br />
android:id="@+id/txt_udatepname"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:hint="product name" /><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginLeft="5dp"<br />
android:text="Enter Product Price" /><br />
<br />
<EditText<br />
android:id="@+id/txt_udatepprice"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_margin="5dp"<br />
android:hint="product price" /><br />
<br />
<Button<br />
android:id="@+id/btn_updaterecord"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_gravity="center"<br />
android:text="Save" /><br />
<br />
</LinearLayout> <br />
<br />
- Here user enter new values for product name and product price so we declare two edittext.<br />
<br />
- Now create new class <b>AddUpdateValues.java</b> for update records.<br />
<br />
<br />
public class AddUpdateValues extends Activity implements OnClickListener {<br />
private Button btn_updaterecord;<br />
private EditText txtpname, txtpprice;<br />
DatabaseHelper db;<br />
ProductModel pm;<br />
Intent i;<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
// TODO Auto-generated method stub<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.addupdatevalues);<br />
i = getIntent();<br />
txtpname = (EditText) findViewById(R.id.txt_udatepname);<br />
txtpprice = (EditText) findViewById(R.id.txt_udatepprice);<br />
<br />
- Here we get string from intent and sets it to perticular field. <br />
<br />
txtpname.setText(i.getExtras().getString("name"));<br />
txtpprice.setText(i.getExtras().getString("price"));<br />
btn_updaterecord = (Button) findViewById(R.id.btn_updaterecord);<br />
btn_updaterecord.setOnClickListener(this);<br />
}<br />
<br />
@Override<br />
public void onClick(View v) {<br />
// TODO Auto-generated method stub<br />
switch (v.getId()) {<br />
case R.id.btn_updaterecord:<br />
if (txtpname.getText().toString().equals("")<br />
|| txtpprice.getText().toString().equals("")) {<br />
Toast.makeText(AddUpdateValues.this, "Please add values..",<br />
Toast.LENGTH_LONG).show();<br />
} else {<br />
<br />
db = new DatabaseHelper(getApplicationContext());<br />
db.getWritableDatabase();<br />
pm = new ProductModel();<br />
pm.productname = txtpname.getText().toString();<br />
pm.productprice = txtpprice.getText().toString();<br />
pm.idno = i.getExtras().getString("id");<br />
db.updateProduct(pm);<br />
Toast.makeText(AddUpdateValues.this,<br />
"Record Update successfully.", Toast.LENGTH_LONG)<br />
.show();<br />
db.close();<br />
super.onResume();<br />
finish(); <br />
}<br />
break;<br />
}<br />
}<br />
}<br />
<br />
<br />
As per many user's request, I have create search functionality in this example.<br />
<br />
Create <b>searchproduct.xml</b> file.<br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:id="@+id/searchlinear"<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:gravity="center_horizontal"<br />
android:orientation="vertical" ><br />
<br />
<LinearLayout<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:orientation="horizontal" ><br />
<br />
<TextView<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_marginBottom="15dp"<br />
android:layout_marginTop="10dp"<br />
android:layout_weight="1"<br />
android:gravity="center"<br />
android:text="Search Record"<br />
android:textSize="18dp"<br />
android:textStyle="bold" /><br />
<br />
<ProgressBar<br />
android:id="@+id/showprogress"<br />
style="?android:attr/progressBarStyleSmall"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_marginTop="10dp"<br />
android:paddingRight="10dp"<br />
android:visibility="gone" /><br />
</LinearLayout><br />
<br />
<EditText<br />
android:id="@+id/txtsearchproduct"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:hint="search"<br />
android:lines="1"<br />
android:paddingLeft="25dp"<br />
android:visibility="visible" ><br />
</EditText><br />
<br />
<AutoCompleteTextView<br />
android:id="@+id/myautocomplete"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:completionThreshold="1"<br />
android:hint="search"<br />
android:lines="1"<br />
android:visibility="gone" /><br />
<br />
<ListView<br />
android:id="@+id/searchlistview"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content" ><br />
</ListView><br />
<br />
</LinearLayout><br />
<br />
<br />
Now for display searched items, we need to create xml file for display single searched item.<br />
<br />
Create <b>product_list.xml</b> for display single searched item.<br />
<br />
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:id="@+id/category_list_id"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:background="@android:color/white"<br />
android:paddingBottom="1dp" ><br />
<br />
<LinearLayout<br />
android:id="@+id/ll_place_name_use"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_centerVertical="true"<br />
android:layout_marginLeft="10dp"<br />
android:layout_marginTop="10dp"<br />
android:orientation="vertical"<br />
android:paddingRight="8dp" ><br />
<br />
<TextView<br />
android:id="@+id/txt_title_text"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:maxLines="3"<br />
android:padding="2dp"<br />
android:text="aaa"<br />
android:textColor="@android:color/black"<br />
android:textSize="16sp"<br />
android:textStyle="bold" ><br />
</TextView><br />
<br />
<TextView<br />
android:id="@+id/txt_price"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content"<br />
android:layout_weight="1"<br />
android:padding="2dp"<br />
android:text="1000"<br />
android:textColor="@android:color/black"<br />
android:textSize="14sp"<br />
android:visibility="visible" ><br />
</TextView><br />
</LinearLayout><br />
<br />
</RelativeLayout><br />
<br />
<br />
Now last but not least create java file for searching.<br />
<br />
Create <b>SearchProduct.java</b><br />
<br />
<br />
package com.androidadvance.screen;<br />
<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
<br />
import com.androidadvance.db.DatabaseHelper;<br />
<br />
import android.app.Activity;<br />
import android.content.Context;<br />
import android.graphics.Color;<br />
import android.os.AsyncTask;<br />
import android.os.Bundle;<br />
import android.os.Handler;<br />
import android.text.Editable;<br />
import android.text.TextWatcher;<br />
import android.util.Log;<br />
import android.view.LayoutInflater;<br />
import android.view.View;<br />
import android.view.ViewGroup;<br />
import android.widget.ArrayAdapter;<br />
import android.widget.AutoCompleteTextView;<br />
import android.widget.BaseAdapter;<br />
import android.widget.EditText;<br />
import android.widget.ImageView;<br />
import android.widget.ListView;<br />
import android.widget.ProgressBar;<br />
import android.widget.RelativeLayout;<br />
import android.widget.TextView;<br />
import android.widget.Toast;<br />
<br />
public class SearchProduct extends Activity implements TextWatcher {<br />
EditText _searchbox;<br />
private ProgressBar showprogress;<br />
searchtask dotask;<br />
private ArrayList<ProductModel> _productList;<br />
ListView _listview;<br />
DatabaseHelper db;<br />
public AutoCompleteTextView myAutoComplete;<br />
private ArrayList<ProductModel> _productList_Temp;<br />
String query = "";<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
// TODO Auto-generated method stub<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.searchproduct);<br />
_searchbox = (EditText) findViewById(R.id.txtsearchproduct);<br />
showprogress = (ProgressBar) findViewById(R.id.showprogress);<br />
_listview = (ListView) findViewById(R.id.searchlistview);<br />
_searchbox.addTextChangedListener(textwatcher);<br />
<br />
}<br />
<br />
Runnable runn = new Runnable() {<br />
<br />
@Override<br />
public void run() {<br />
// TODO Auto-generated method stub<br />
handlersearch.sendEmptyMessage(0);<br />
}<br />
};<br />
TextWatcher textwatcher = new TextWatcher() {<br />
<br />
public void onTextChanged(CharSequence s, int start, int before,<br />
int count) {<br />
Log.i("---onTextChanged ----", "---------onTextChanged ----");<br />
<br />
if (_searchbox.getText().toString().length() > 2) {<br />
query = _searchbox.getText().toString().replace(" ", "%20");<br />
<br />
handlersearch.removeCallbacks(runn);<br />
handlersearch.post(runn);<br />
<br />
} else {<br />
showprogress.setVisibility(View.GONE);<br />
<br />
if (dotask != null) {<br />
if (dotask.getStatus().equals(AsyncTask.Status.RUNNING)) {<br />
dotask.cancel(true);<br />
}<br />
}<br />
<br />
handlersearch.removeCallbacks(runn);<br />
<br />
_productList = new ArrayList<ProductModel>();<br />
_productList.clear();<br />
_listview.setAdapter(new CustomBaseAdapter(SearchProduct.this,<br />
_productList));<br />
}<br />
<br />
}<br />
<br />
public void beforeTextChanged(CharSequence s, int start, int count,<br />
int after) {<br />
// TODO Auto-generated method stub<br />
<br />
}<br />
<br />
public void afterTextChanged(Editable s) {<br />
// TODO Auto-generated method stub<br />
<br />
}<br />
};<br />
<br />
Handler handlersearch = new Handler() {<br />
<br />
public void handleMessage(android.os.Message msg) {<br />
dotask = new searchtask();<br />
dotask.execute();<br />
};<br />
};<br />
<br />
private class searchtask extends AsyncTask<Void, Void, Void> {<br />
<br />
protected void onPreExecute() {<br />
<br />
showprogress.setVisibility(View.VISIBLE);<br />
};<br />
<br />
protected void onPostExecute(Void param) {<br />
// animation.dismiss();<br />
showprogress.setVisibility(View.GONE);<br />
if (_productList == null)<br />
return;<br />
<br />
ArrayList<String> item = new ArrayList<String>();<br />
<br />
for (int i = 0; i < _productList.size(); i++) {<br />
item.add(_productList.get(i).productname);<br />
}<br />
<br />
myAutoComplete = (AutoCompleteTextView) findViewById(R.id.myautocomplete);<br />
<br />
myAutoComplete.addTextChangedListener(SearchProduct.this);<br />
<br />
myAutoComplete.setAdapter(new ArrayAdapter<String>(<br />
SearchProduct.this,<br />
android.R.layout.simple_dropdown_item_1line, item));<br />
<br />
_productList_Temp = new ArrayList<ProductModel>();<br />
<br />
for (int i = 0; i < _productList.size(); i++) {<br />
<br />
_productList_Temp.add(_productList.get(i));<br />
<br />
}<br />
<br />
_listview.setAdapter(new CustomBaseAdapter(SearchProduct.this,<br />
_productList_Temp));<br />
<br />
}<br />
<br />
@Override<br />
protected Void doInBackground(Void... params) {<br />
<br />
db = new DatabaseHelper(getApplicationContext());<br />
db.getWritableDatabase();<br />
ArrayList<ProductModel> product_list = db.getProudcts(query);<br />
<br />
for (int i = 0; i < product_list.size(); i++) {<br />
<br />
String tidno = product_list.get(i).getIdno();<br />
<br />
System.out.println("tidno>>>>>" + tidno);<br />
String tname = product_list.get(i).getProductname();<br />
String tprice = product_list.get(i).getProductprice();<br />
<br />
ProductModel _ProductModel = new ProductModel();<br />
<br />
_ProductModel.setIdno(tidno);<br />
_ProductModel.setProductname(tname);<br />
_ProductModel.setProductprice(tprice);<br />
<br />
_productList.add(_ProductModel);<br />
}<br />
// _productList = _parser.getProductList();<br />
<br />
return null;<br />
}<br />
<br />
}<br />
<br />
private class CustomBaseAdapter extends BaseAdapter {<br />
LayoutInflater _inflater;<br />
<br />
List<ProductModel> productList;<br />
<br />
public CustomBaseAdapter(Context context, List<ProductModel> productList) {<br />
_inflater = LayoutInflater.from(context);<br />
this.productList = productList;<br />
<br />
}<br />
<br />
public int getCount() {<br />
// TODO Auto-generated method stub<br />
return productList.size();<br />
}<br />
<br />
public Object getItem(int position) {<br />
// TODO Auto-generated method stub<br />
return position;<br />
}<br />
<br />
public long getItemId(int position) {<br />
// TODO Auto-generated method stub<br />
return position;<br />
}<br />
<br />
public View getView(int position, View convertView, ViewGroup parent) {<br />
<br />
ViewHolder _holder;<br />
if (convertView == null) {<br />
<br />
convertView = _inflater.inflate(R.layout.product_list, null);<br />
_holder = new ViewHolder();<br />
<br />
_holder.title = (TextView) convertView<br />
.findViewById(R.id.txt_title_text);<br />
_holder.price = (TextView) convertView<br />
.findViewById(R.id.txt_price);<br />
<br />
convertView.setTag(_holder);<br />
} else {<br />
_holder = (ViewHolder) convertView.getTag();<br />
}<br />
<br />
_holder.title.setText(productList.get(position).productname.trim());<br />
<br />
_holder.price.setText(productList.get(position).productprice);<br />
<br />
return convertView;<br />
}<br />
<br />
private class ViewHolder {<br />
TextView title;<br />
TextView price;<br />
}<br />
}<br />
<br />
@Override<br />
public void afterTextChanged(Editable arg0) {<br />
// TODO Auto-generated method stub<br />
<br />
}<br />
<br />
@Override<br />
public void beforeTextChanged(CharSequence s, int start, int count,<br />
int after) {<br />
// TODO Auto-generated method stub<br />
<br />
}<br />
<br />
@Override<br />
public void onTextChanged(CharSequence s, int start, int before, int count) {<br />
// TODO Auto-generated method stub<br />
<br />
}<br />
<br />
//<br />
}<br />
<br />
<br />
<br />
<span style="font-size: large;"><b><a href="http://www.mediafire.com/?9z9v10mqk9b9dd0" target="_blank">Download Source code</a></b></span></div>Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com68tag:blogger.com,1999:blog-6606063074222360634.post-27258741392824145352013-04-02T02:45:00.001-07:002013-04-02T02:50:13.126-07:00Shared Preferences in Android<div dir="ltr" style="text-align: left;" trbidi="on">
In android one of the way using which you can store data is using <a href="http://developer.android.com/reference/android/content/SharedPreferences.html" title="">shared preferences</a>.
You can also store data in global variable and use it but in that
Global data will lost when user close the application. While with Shared
preferences data will be persistent even if user close the application.<br />
<br />
For example for login form generally all login form have concept for
remember password. In android you acieve this type of functionality by
using SharedPreferences.<br />
<br />
Example :-<br />
<br />
<b>-></b> <b>How to Initialization </b><br />
<br />
SharedPreferences _mypref = getApplicationContext().getSharedPreferences("mypref", 0); <--- 0 - for private<br />
<br />
<br />
Editor editor = _mypref.edit();<br />
<br />
<b> -> How to store data in shared preferences</b><br />
<br />
<br />
Storing boolean - true/false <br />
<br />
editor.putBoolean("key_name", true); <br />
<br />
Storing string<br />
<br />
editor.putString("key_name", "string value");<br />
<br />
Storing integer<br />
<br />
editor.putInt("key_name", "int value"); <br />
<br />
Storing float<br />
<br />
editor.putFloat("key_name", "float value"); <br />
<br />
Storing long <br />
<br />
editor.putLong("key_name", "long value"); <br />
<br />
commit changes<br />
<br />
editor.commit(); <br />
<br />
<br />
<br />
<b>-> How to Retrieving Data</b><br />
<br />
getting String<br />
_mypref .getString("key_name", null); <br />
<br />
getting Integer<br />
<br />
_mypref .getInt("key_name", null); <br />
<br />
getting Float<br />
<br />
_mypref .getFloat("key_name", null); <br />
<br />
getting Long<br />
<br />
_mypref .getLong("key_name", null); <br />
<br />
<br />
getting boolean<br />
<br />
_mypref.getBoolean("key_name", null); <br />
<br />
<br />
<b>-> How to remove Data</b><br />
<br />
<br />
editor.remove("name");<br />
editor.commit();<br />
<br />
<br />
<br />
<b> -> How to Clear all Data </b><br />
<br />
<br />
editor.clear();<br />
editor.commit();</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-88273287499542586412013-04-02T02:36:00.000-07:002013-04-02T02:44:02.705-07:00Storing Data on Android Platform<div dir="ltr" style="text-align: left;" trbidi="on">
So we can say that There are 4 ways of storing data on the android platform:<br />
<br />
1) Shared Preferences <br />
2) Sqlite Database<br />
3) File / directory<br />
4) store data in server by using web service<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-58316347890793033122013-04-02T02:31:00.000-07:002013-04-02T02:33:19.855-07:00Security and Permissions<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;"> Applications as Operating System Users<br /> Explicitly Defined Application Permissions<br /> Limited Ad-Hoc Permissions<br /> Application Signing for Trust Relationships<br /> Marketplace Developer Registration.</span><br />
<br />
<br />
<h2 style="text-align: left;">
Applications as Operating System Users</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><strong>=></strong>When an application is installed, the operating system creates a new user profile associated with the application.<br /><span></span><br /><span></span><strong>=></strong>Each
application runs as a different user, with its own private files on the
file system, a user ID, and a secure operating environment.<br /><span></span><br /><span></span><strong>=></strong>The
application executes in its own process with its own instance of the
Dalvik VM and under its own user ID on the operating system.</span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><br /> </span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><br /> </span></div>
<h2>
Explicitly Defined Application Permissions</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><strong>=></strong>To access shared resources on the system, Android applications register for the specific privileges they require.<br /><span><br /><span></span><strong>=></strong>Some
of these privileges enable the application to use phone functionality
to make calls, access the network, and control the camera and other
hardware sensors.<br /><span></span><br /><span></span><strong>=></strong>Applications also require permission to access shared data containing private <br /> and personal information, such as user preferences, user’s location, and contact <br /> information.<br /><span></span><br /><span></span></span></span></div>
<h2 style="text-align: left;">
Limited Ad-Hoc Permissions </h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><strong>=></strong>Applications
that act as content providers might want to provide some on-the-fly
permissions to other applications for specific information they want to
share openly.<br /><span></span><br /><span></span><strong>=></strong>This is done using ad-hoc granting and revoking of access to specific resources using Uniform Resource Identifiers (URIs). <br /><span></span><br /><span></span><strong>=></strong>URIs index specific data assets on the system, such as images and text.<br /><span></span><br /><span></span><strong>=></strong>An example of a URI that provides the phone numbers of all contacts:<br /><span> content://contacts/phones<br /><span></span> Example:<br /><span></span> Birthday public & private wish list.<br /><span></span><br /><span></span><strong>=></strong>Application Signing for Trust Relationship.</span></span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><span> </span></span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><span> </span></span></div>
<h2 style="text-align: left;">
Application Signing for Trust Relationships</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><strong>=></strong>All Android applications packages (.apk) are signed with a certificate, so users know that the application is authentic.<br /><span><br /><span></span><strong>=></strong>The
private key for the certificate is held by the developer.This helps
establish a trust relationship between the developer and the user.<br /><span><br /><span><strong>=></strong>No certificate authority is necessary; self-signed certificates are acceptable.</span></span></span></span></div>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><span><span><span> </span></span></span></span></div>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><span><span><span> </span></span></span></span></div>
<h2 style="text-align: left;">
Marketplace Developer Registration</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><strong>=></strong>To publish applications on the popular Android Market, developers must create a developer account.<br /><span><br /><span></span><strong>=></strong>The Android Market is managed closely and no malware is tolerated.</span></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-67994018624229610242013-04-02T02:30:00.003-07:002013-04-02T02:32:39.734-07:00Android Features<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;"> Free and Open Source<br /> Familiar and Inexpensive Development Tools<br /> Freely Available Software Development Kit<br /> Familiar Language, Familiar Development Environments<br /> Reasonable Learning Curve for Developers<br /> Enabling Development of Powerful Applications<br /> Rich, Secure Application Integration<br /> No Costly Obstacles to Publication<br /> A “Free Market” for Applications<br /> A New and Growing Platform. </span><br />
<br />
<br />
<h2>
Free and Open Source platform</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>Android
is an open source platform. Neither developers nor handset
manufacturers pay royalties or license fees to develop for the platform.<br /><br /><b>=></b>The
underlying operating system of Android is licensed under GNU General
Public License Version 2 (GPLv2), a strong “copyleft” license where any
third-party improvements must continue to fall under the open source
licensing agreement <br /> terms.<br /><br /><b>=></b>The Android framework is distributed under the Apache Software License (ASL/Apache2),<br />which allows for the distribution of both open- and closed-source derivations of the source code.<br /><br /><b>=></b>Commercial
developers (handset manufacturers especially) can choose to enhance the
platform without having to provide their improvements to the open
source community.<br /><br /><b>=></b>Developers
can profit from enhancements such as handset-specific improvements and
redistribute their work under whatever licensing they want.<br /><br /><b>=></b>Developers can write open source freeware or traditional licensed applications for profit and everything in between.</span><br />
</div>
<h2 style="text-align: left;">
Familiar and Inexpensive Development Tools</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><b>=></b>Developer
doesn’t require registration fees, vetting, and expensive compilers,
there are no upfront costs of developing Android applications.</span><br />
</div>
<h2 style="text-align: left;">
Freely Available Software Development Kit</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><b>=></b>The Android SDK and tools are freely available.<br /><br /><b>=></b>Developers can download the Android SDK from the Android website after agreeing <br /> to the terms of the Android Software Development Kit License Agreement.</span><br />
<br />
</div>
<h2 style="text-align: left;">
Familiar Language, Familiar Development Environments.</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>Eclipse
is the most popular IDE for Android development, and there is an
Android plug-in available for facilitating Android development.</span><br />
<br />
</div>
<h2 style="text-align: left;">
Reasonable Learning Curve for Developers</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>Android applications are written in a well-respected programming language: Java<br /><br /><b>=></b>Developers can rely on familiar class libraries (java.net, java.text..)..<br /><br /><b>=></b>Specialty
libraries for tasks such as graphics and database management are
implemented using well-defined open standards such as OpenGL Embedded
Systems (OpenGL ES) or SQLite.</span><br />
<br />
</div>
<h2 style="text-align: left;">
Enabling Development of Powerful Applications</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><b>=></b>The
manufacturer would grant the developer privileged inside access and
knowledge of a handset’s internal software framework and firmware.</span><br />
<br />
</div>
<h2 style="text-align: left;">
Rich, Secure Application Integration</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>Text messaging, phone dialer, camera, email, picture, messaging, and the browser.<br /><br /><b>=></b>Each was a separate application running on the phone— some built-in and some purchased.Each had its own unique user interface.</span><br />
<br />
</div>
<h2 style="text-align: left;">
No Costly Obstacles to Publication</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>Android
applications have none of the costly and time-intensive testing and
certification programs required by other platforms such as BREW and
Symbian</span>.<br />
<br />
</div>
<h2 style="text-align: left;">
A “Free Market” for Applications</h2>
<div class="paragraph" style="display: block; text-align: left;">
<span style="font-size: small;"><b>=></b>Android developers are free to choose any kind of revenue model they want.</span><br />
<br />
</div>
<h2 style="text-align: left;">
A New and Growing Platform</h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"><b>=></b>In
recent revisions, the Android platform has received some much needed UI
“polish,” both in terms of visual appeal and performance.<br /><br /><b>=></b>A
number of published applications have required retesting and
resubmission to the Android Marketplace to conform to new SDK
requirements, which are quickly rolled out to all Android phones in the
field as a firmware upgrade, rendering older applications obsolete.</span></div>
<br />
<span style="font-size: small;"><br /></span>
<span style="font-size: small;"> </span></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-45630909718956370372013-04-02T02:29:00.006-07:002013-04-02T02:29:52.165-07:004.Android Platform Differences<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #33ccff; font-size: small;"><u>A.</u></span><span style="color: #33ccff;"><span style="font-size: small;"><span style="color: #33ccff;"><strong><u>Complete</u>:</strong> </span><span style="color: #cccccc;"><span style="color: #999999;"><span style="color: black;">The
designers took a comprehensive approach when they developed the Android
platform.They began with a secure operating system and built a robust
software framework on top that allows for rich application development
opportunities</span>.<br /><strong> <br /><span style="color: #33ccff;"><u>B.Open</u>: </span></strong><span style="color: silver;"><span style="color: #999999;"><span style="color: black;">The Android platform is provided through open source licensing. <br /><span></span></span><br /><span></span></span><span style="color: #33ccff;"><strong><u>C.Free</u>: </strong></span></span></span></span><span style="color: black;">Android applications are free to develop.<br /><span></span> There are no licensing or royalty fees to develop on the platform.<br /><span></span> No requirement of membership fees.<br /><span></span> No requirement of testing fees.<br /><span></span> No requirement of signing or certification fees.<br /><span></span> Android applications can be distributed and commercialized in a variety of ways.</span></span></span></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-48601957891066130472013-04-02T02:29:00.002-07:002013-04-02T02:29:24.967-07:003.Open Handset Alliance (OHA)<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;">What would it take to build a better mobile phone? <br /><span></span><br /><span></span>The Open Handset Alliance (OHA) was formed in November 2007 to answer that very question. <br /><span></span><br /><span></span>The OHA is a business alliance comprised of many of the largest and most successful mobile companies on the planet. <br /><span></span><br /><span></span>Its members include chip makers, handset manufacturers, software developers, and service providers. </span></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-68058459494599126212013-04-02T02:28:00.000-07:002013-04-02T02:28:07.044-07:002.History about Android<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;"><strong>=></strong>Andy Rubin has been credited as the father of the Android platform.<br /><span></span><br /><strong>=></strong>Working
together, OHA members, including Google, began developing a
nonproprietary open standard platform based upon technology developed at
Android Inc.<br /><span></span><br /><span></span><strong>=></strong>Google’s involvement in the Android project is very extensive.<br /><span></span><br /><span></span><strong>=></strong>Google hosts the Android open source project and provides<br /> <strong>-</strong>Online Android Documentation<br /><span></span> <strong>-</strong>Tools<br /><span></span> <strong>-</strong>Forums<br /><span></span> <strong>-</strong>Software Development Kit (SDK) for Developer<br /><br /><span></span><strong>=></strong>All major Android news originates at Google. <br /><span></span><br /><span></span><strong>=></strong>The
company has also hosted a number of events at conferences and the
Android Developer Challenge (ADC), a contest to encourage developers
to write killer Android applications.</span></div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0tag:blogger.com,1999:blog-6606063074222360634.post-44211158372259230252013-04-02T02:27:00.002-07:002013-04-02T02:27:19.571-07:001.What is Android ?<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<br /></h2>
<div class="paragraph" style="display: block;">
<span style="font-size: small;">Android is
an middlewere OS for mobile key Application. Android Inc. founded by
Andi rubin,Rich Min_er,Nick Sears and Chris White in 2003. Later
Android Inc. equiped by Google in 2005.</span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"> </span></div>
<div class="paragraph" style="display: block;">
<span style="font-size: small;"> </span></div>
</div>
Anonymoushttp://www.blogger.com/profile/06359822112357998419noreply@blogger.com0