Jumat, 29 April 2011

Deleting A Particular Row in listView Using getView method

In My Previous Posts i Explained How to Add ImageView And CheckBox And Edit Text and Some Related tasks .
 
In this post I am Giving Simple Explanations about How to Delete a Particular row Selected By User , when user Clicks A button in List View simple its Removed selected Row and Refresh getView Method.

In this ListView contains in ImageView, TextView ,EditText,TextView ,And Button
in a single Row  .

files :

===
cart.xml ( for ListView Layout view )
cartitems.xml ( listView Items )
cartAdapter.java ( For ListView Items and major operations  )
Viewcart.java ( ListView Operations)

cart.xml
------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/bg">

    <Button android:id="@+id/btnChkOut" android:layout_width="80dip"
        android:layout_height="wrap_content" android:text="Checkout" />

    <Button android:id="@+id/btnGT" android:layout_width="88dip"
        android:layout_toRightOf="@+id/btnChkOut" android:layout_height="wrap_content"
        android:text="Get Total :" />

    <TextView android:id="@+id/tvGTotal" android:layout_width="60dip"
        android:textStyle="bold" android:layout_marginTop="12dip"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/btnGT"
        android:textColor="#000000" />
    <Button android:id="@+id/btnCont" android:layout_width="50dip"
        android:layout_height="40dip" android:background="@drawable/home"
        android:layout_alignParentRight="true" />

    <ListView android:layout_below="@+id/btnChkOut" android:id="@+id/listViewCart"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
</RelativeLayout>





cartitems.xml
------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/imgView" android:layout_width="90dip"
        android:layout_height="80dip" />
    <TextView android:layout_marginTop="10dip" android:id="@+id/tvPrice"
        android:layout_width="80dip" android:layout_height="20dip"
        android:hint="price" android:layout_toRightOf="@+id/imgView"
        android:textStyle="bold" android:textColor="#000000" />
    <EditText android:id="@+id/etQuantity" android:layout_width="60dip"
        android:layout_height="35dip" android:layout_toRightOf="@+id/tvPrice"
        android:textSize="13sp" android:layout_marginTop="10dip" android:text="1"
        android:gravity="center" android:inputType="number" />
    <TextView android:id="@+id/tvTotal" android:layout_width="80dip"
        android:layout_height="20dip" android:hint="total"
        android:layout_toRightOf="@+id/etQuantity" android:paddingLeft="20dip"
        android:textStyle="bold" android:layout_marginTop="10dip"
        android:textColor="#000000" />
        <Button  
        android:background="@drawable/del"
        android:layout_below="@+id/etQuantity"
        android:id="@+id/btnDC"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/etQuantity"
        android:layout_marginLeft="40dip"
       
        />
</RelativeLayout>

cartadapter.java
----------------------------
package gadgetstore.utils;

import gadgetstore.screens.R;
import gadgetstore.screens.ViewCart;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class CartAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private Context mContext;
    public Double tot = 0.0;
    public Set<DataBean> mCart = null;
    public ArrayList<DataBean> cartList = new ArrayList<DataBean>();
    public HashMap<Integer, String> mQuantity = new HashMap<Integer, String>();
    public HashMap<Integer, Double> mPrice = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total1 = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total2 = new HashMap<Integer, Double>();
    int mPosition;
    private Iterator<DataBean> mCbean;
    public String price = "41";
    public Double pr = 0.0;

    public CartAdapter(Context context, Set<DataBean> data,
            LayoutInflater inflater) {
        cartList.clear();
        total.clear();
        total1.clear();
        total2.clear();
        mCart = data;
        mCbean = null;
        mContext = context;
        mLayoutInflater = inflater;
        mCbean = mCart.iterator();
        while (mCbean.hasNext()) {
            DataBean db = (DataBean) mCbean.next();
            cartList.add(db);
        }
        getTotalPrice();
    }

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

    @Override
    public Object getItem(int arg0) {

        return null;
    }

    @Override
    public long getItemId(int arg0) {

        return 0;
    }

    int count = 0;

    @Override
    public View getView(int position, View arg1, ViewGroup arg2) {
        final int pos = position;
        final View vv = arg1;
        final DataBean dbObj = cartList.get(position);
        final View v = mLayoutInflater.inflate(R.layout.cartitems, null);
        ImageView img = (ImageView) v.findViewById(R.id.imgView);
        final Button btnDC = (Button) v.findViewById(R.id.btnDC);
        btnDC.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                // deleting a item for array list
                StaticUtils.sCart.remove(cartList.get(pos));
                // calling activty for listview refresh when u clik a button
                Intent myIntent = new Intent(vv.getContext(), ViewCart.class);
                vv.getContext().startActivity(myIntent);
               

            }
        });
        int im = mContext.getResources().getIdentifier(dbObj.getImgpath(),
                "raw", mContext.getPackageName());
        img.setBackgroundResource(im);
        final TextView tv = (TextView) v.findViewById(R.id.tvPrice);
        tv.setText(dbObj.getPrice());
        final EditText etQuan = (EditText) v.findViewById(R.id.etQuantity);

        final TextView brprice = (TextView) v.findViewById(R.id.tvTotal);
        brprice.setText(dbObj.getPrice());
        total.put(position, Double.parseDouble(dbObj.getPrice()));
        pr = pr + Double.parseDouble(brprice.getText().toString());
        mPosition = position;
        if (count != 0) {
            try {
                if (count != 0) {
                    String st = mQuantity.get(pos);
                    if (st.length() != 0)
                        etQuan.setText(st);
                    Double price = mPrice.get(pos);
                    if (price != null)
                        brprice.setText(price + "");

                }
            } catch (NullPointerException e) {

            }

        }

        etQuan.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {

                int quan;
                try {
                    mQuantity.put(pos, etQuan.getText().toString());
                    quan = Integer.parseInt(etQuan.getText().toString());
                } catch (NumberFormatException e) {
                    quan = 1;
                }
                double tprice = Double.parseDouble(dbObj.getPrice());
                brprice.setText("" + (tprice * quan));

                total.put(pos, (Double.parseDouble(dbObj.getPrice()) * quan));
                total1 = total;

                mPrice.put(pos, (tprice * quan));
                count++;
                price = quan + "";

            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {

            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            }
        });

        total2.put(position, Double.parseDouble(etQuan.getText().toString()));

        return v;
    }

    public static HashMap<Integer, Double> getTotalPrice() {

        return total;

    }

    public static HashMap<Integer, Double> getQunatity() {
        return total2;
    }

    public ArrayList<DataBean> getCartlist() {
        return cartList;
    }
}


viewCrt.java
-------------------
package gadgetstore.screens;

import gadgetstore.utils.CartAdapter;
import gadgetstore.utils.DataBean;
import gadgetstore.utils.StaticUtils;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ViewCart extends Activity implements OnClickListener {
    private ListView lv;
    private LayoutInflater mLayoutInflater = null;
    public ArrayList<DataBean> mCList;
    double totPrice;
    private Button mBtnCheckout, mBtnGt, mBtnContShop;
    private TextView mTvGt;

    public ViewCart() {
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cart);
        lv = (ListView) findViewById(R.id.listViewCart);
        mLayoutInflater = getLayoutInflater();
        final CartAdapter lAdapter = new CartAdapter(getApplicationContext(),
                StaticUtils.sCart, mLayoutInflater);
        try {
            lv.setAdapter(lAdapter);
            lv.setCacheColorHint(0);
            mCList = lAdapter.getCartlist();
            mBtnCheckout = (Button) findViewById(R.id.btnChkOut);
            mBtnGt = (Button) findViewById(R.id.btnGT);
            mTvGt = (TextView) findViewById(R.id.tvGTotal);
            mBtnCheckout.setOnClickListener(this);
            mBtnGt.setOnClickListener(this);
            mBtnContShop = (Button) findViewById(R.id.btnCont);
            mBtnContShop.setOnClickListener(this);
        } catch (Exception e) {
            Log.w(" view cart exception ", e.toString());
        }

    }

    @Override
    public void onClick(View v) {
        if (v == mBtnCheckout) {
            startActivity(new Intent(ViewCart.this, PaypalScreen.class));
        } else if (v == mBtnGt) {

            try {

                HashMap<Integer, Double> price = new HashMap<Integer, Double>();

                price = CartAdapter.getTotalPrice();

                HashMap<Integer, Double> quantity = new HashMap<Integer, Double>();

                quantity = CartAdapter.getQunatity();
                int si = quantity.size();

                double d = 0.0;
                for (int j = 0; j < si; j++) {
                    d = (quantity.get(j) * price.get(j)) + d;

                }

                mTvGt.setText("  " + d);

            } catch (Exception e) {
                Log.w(" error ", e.toString());
            }

        } else if (v == mBtnContShop) {
            startActivity(new Intent(ViewCart.this, HomeScreenTab.class));
        }

    }

}



For Source Code Click Here

Kamis, 28 April 2011

Read Text From the Raw Content in Resource Folder.

You can store the raw content in the raw folder and read using the below method..
1. Create a file in and Raw content
2. Create Method called readTextResource() in the util class
3. Use the below code to read the data
StringBuffer strBuffer = new StringBuffer();
InputStream inputStream = null;
try {
inputStream = owner.getResources().openRawResource(resourceId);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String str = br.readLine();
while (str != null) {
strBuffer.append(str);
str = br.readLine();
}
} catch (IOException e) {
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
}
}
4. Return the StringBuffer value.
5. If you need a html format, you can use the html util class
Html.fromHtml(text); - It returns Spanned instance.

Sample Code
-----------
public class MainActivity extends Activity {

private Spanned mText = null;
private TextView mTextView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView = (TextView) findViewById(R.id.sampleText);
if (mText == null) {
String text = readTextResource(R.raw.license, this);
mText = Html.fromHtml(text);
}
mTextView.setText(mText);
}
public String readTextResource(int resourceId, Activity owner) {
StringBuffer strBuffer = new StringBuffer();
InputStream inputStream = null;
try {
inputStream = owner.getResources().openRawResource(resourceId);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String str = br.readLine();
while (str != null) {
strBuffer.append(str);
str = br.readLine();
}
} catch (IOException e) {
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
}
}
return strBuffer.toString();
}
}

Selasa, 26 April 2011

Tab Layout ( Tab Host , Tab Widget )


Tab Layout

To create a tabbed UI, you need to use a TabHost and a TabWidget. The TabHost must be the root node for the layout, which contains both theTabWidget for displaying the tabs and a FrameLayout for displaying the tab content.
You can implement your tab content in one of two ways: use the tabs to swap Views within the same Activity, or use the tabs to change between entirely separate activities. Which method you want for your application will depend on your demands, but if each tab provides a distinct user activity, then it probably makes sense to use a separate Activity for each tab, so that you can better manage the application in discrete groups, rather than one massive application and layout.
In this tutorial, you'll create a tabbed UI that uses a separate Activity for each tab.
  1. Start a new project named HelloTabWidget.
  2. First, create three separate Activity classes in your project: ArtistsActivityAlbumsActivity, and SongsActivity. These will each represent a separate tab. For now, make each one display a simple message using a TextView. For example:
    public class ArtistsActivity extends Activity {
       
    public void onCreate(Bundle savedInstanceState) {
           
    super.onCreate(savedInstanceState);

           
    TextView textview = new TextView(this);
            textview
    .setText("This is the Artists tab");
            setContentView
    (textview);
       
    }
    }
    Notice that this doesn't use a layout file. Just create a TextView, give it some text and set that as the content. Duplicate this for each of the three activities, and add the corresponding <activity/> tags to the Android Manifest file.
  3. You need an icon for each of your tabs. For each icon, you should create two versions: one for when the tab is selected and one for when it is unselected. The general design recommendation is for the selected icon to be a dark color (grey), and the unselected icon to be a light color (white). (See the Icon Design Guidelines.) For example:
     
    For this tutorial, you can copy these images and use them for all three tabs. (When you create tabs in your own application, you should create customized tab icons.)
    Now create a state-list drawable that specifies which image to use for each tab state:
    1. Save the icon images in your project res/drawable/ directory.
    2. Create a new XML file in res/drawable/ named ic_tab_artists.xml and insert the following:
      <?xml version="1.0" encoding="utf-8"?>
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
         
      <!-- When selected, use grey -->
         
      <item android:drawable="@drawable/ic_tab_artists_grey"
               
      android:state_selected="true" />
         
      <!-- When not selected, use white-->
         
      <item android:drawable="@drawable/ic_tab_artists_white" />
      </selector>
      This is a state-list drawable, which you will apply as the tab image. When the tab state changes, the tab icon will automatically switch between the images defined here.
  4. Open the res/layout/main.xml file and insert the following:
    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
       
    android:id="@android:id/tabhost"
       
    android:layout_width="fill_parent"
       
    android:layout_height="fill_parent">
       
    <LinearLayout
           
    android:orientation="vertical"
           
    android:layout_width="fill_parent"
           
    android:layout_height="fill_parent"
           
    android:padding="5dp">
           
    <TabWidget
               
    android:id="@android:id/tabs"
               
    android:layout_width="fill_parent"
               
    android:layout_height="wrap_content" />
           
    <FrameLayout
               
    android:id="@android:id/tabcontent"
               
    android:layout_width="fill_parent"
               
    android:layout_height="fill_parent"
               
    android:padding="5dp" />
       
    </LinearLayout>
    </TabHost>
    This is the layout that will display the tabs and provide navigation between each Activity created above.
    The TabHost requires that a TabWidget and a FrameLayout both live somewhere within it. To position the TabWidget and FrameLayoutvertically, a LinearLayout is used. The FrameLayout is where the content for each tab goes, which is empty now because the TabHost will automatically embed each Activity within it.
    Notice that the TabWidget and the FrameLayout elements have the IDs tabs and tabcontent, respectively. These names must be used so that the TabHost can retrieve references to each of them. It expects exactly these names.
  5. Now open HelloTabWidget.java and make it extend TabActivity:
    public class HelloTabWidget extends TabActivity {
  6. Use the following code for the onCreate() method:
    public void onCreate(Bundle savedInstanceState) {
       
    super.onCreate(savedInstanceState);
        setContentView
    (R.layout.main);

       
    Resources res = getResources(); // Resource object to get Drawables
       
    TabHost tabHost = getTabHost();  // The activity TabHost
       
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
       
    Intent intent;  // Reusable Intent for each tab

       
    // Create an Intent to launch an Activity for the tab (to be reused)
        intent
    = new Intent().setClass(this, ArtistsActivity.class);

       
    // Initialize a TabSpec for each tab and add it to the TabHost
        spec
    = tabHost.newTabSpec("artists").setIndicator("Artists",
                          res
    .getDrawable(R.drawable.ic_tab_artists))
                     
    .setContent(intent);
        tabHost
    .addTab(spec);

       
    // Do the same for the other tabs
        intent
    = new Intent().setClass(this, AlbumsActivity.class);
        spec
    = tabHost.newTabSpec("albums").setIndicator("Albums",
                          res
    .getDrawable(R.drawable.ic_tab_albums))
                     
    .setContent(intent);
        tabHost
    .addTab(spec);

        intent
    = new Intent().setClass(this, SongsActivity.class);
        spec
    = tabHost.newTabSpec("songs").setIndicator("Songs",
                          res
    .getDrawable(R.drawable.ic_tab_songs))
                     
    .setContent(intent);
        tabHost
    .addTab(spec);

        tabHost
    .setCurrentTab(2);
    }
    This sets up each tab with their text and icon, and assigns each one an Activity.
    A reference to the TabHost is first captured with getTabHost(). Then, for each tab, a TabHost.TabSpec is created to define the tab properties. The newTabSpec(String) method creates a new TabHost.TabSpec identified by the given string tag. For each TabHost.TabSpec,setIndicator(CharSequence, Drawable) is called to set the text and icon for the tab, and setContent(Intent) is called to specify theIntent to open the appropriate Activity. Each TabHost.TabSpec is then added to the TabHost by calling addTab(TabHost.TabSpec).
    At the very end, setCurrentTab(int) opens the tab to be displayed by default, specified by the index position of the tab.
    Notice that not once was the TabWidget object referenced. This is because a TabWidget must always be a child of a TabHost, which is what you use for almost all interaction with the tabs. So when a tab is added to the TabHost, it's automatically added to the child TabWidget.
  7. Now open the Android Manifest file and add the NoTitleBar theme to the HelloTabWidget's <activity> tag. This will remove the default application title from the top of the layout, leaving more space for the tabs, which effectively operate as their own titles. The <activity> tag should look like this:
    <activity android:name=".HelloTabWidget" android:label="@string/app_name"
             
    android:theme="@android:style/Theme.NoTitleBar">
  8. Run the application.
Your application should look like this (though your icons may be different):

References

ImageView TextView Edittext in List View using getview method And Calculating Grand Total in android

In this programing i am explaing code For To display Image and Text and EditText in Single Colum in ListView

files :
-------
cart.xml
cartitems.xml
cartAdapter.java
CartDetails.java

cart.xml :
======
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/bg">
  
    <Button android:id="@+id/btnChkOut" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Checkout" />
      
        <Button android:id="@+id/btnGT" android:layout_width="wrap_content"
        android:layout_toRightOf="@+id/btnChkOut"
        android:layout_height="wrap_content" android:text="Get Total :" />
      
    <TextView android:id="@+id/tvGTotal" android:layout_width="wrap_content"
    android:layout_marginTop="10dip"
    android:textStyle="bold"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/btnGT"
        android:paddingLeft="20dip" android:textColor="#000000" />
      
    <ListView android:layout_below="@+id/btnChkOut" android:id="@+id/listViewCart"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
</RelativeLayout>

cartitems.xml
-------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/imgView" android:layout_width="90dip"
        android:layout_height="80dip" />
    <TextView android:layout_marginTop="10dip" android:id="@+id/tvPrice"
        android:layout_width="80dip" android:layout_height="20dip"
        android:hint="price" android:layout_toRightOf="@+id/imgView"
        android:textStyle="bold" android:textColor="#000000" />
    <EditText android:id="@+id/etQuantity" android:layout_width="60dip"
        android:layout_height="35dip" android:layout_toRightOf="@+id/tvPrice"
        android:textSize="13sp" android:layout_marginTop="10dip" android:text="1"
        android:gravity="center" android:inputType="number" />
    <TextView android:id="@+id/tvTotal" android:layout_width="80dip"
        android:layout_height="20dip" android:hint="total"
        android:layout_toRightOf="@+id/etQuantity" android:paddingLeft="20dip"
        android:textStyle="bold" android:layout_marginTop="10dip"
        android:textColor="#000000" />
</RelativeLayout>

CartAdapter.java
-----------------------
package gadgetstore.utils;

import gadgetstore.screens.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class CartAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private Context mContext;
    public Double tot = 0.0;
    public Set<DataBean> mCart;
    public ArrayList<DataBean> cartList = new ArrayList<DataBean>();
    public HashMap<Integer, String> mQuantity = new HashMap<Integer, String>();
    public HashMap<Integer, Double> mPrice = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total1 = new HashMap<Integer, Double>();
    public static HashMap<Integer, Double> total2 = new HashMap<Integer, Double>();
    int mPosition;
    private Iterator<DataBean> mCbean;
    public String price = "41";
    public Double pr = 0.0;

    public CartAdapter(Context context, Set<DataBean> data,
            LayoutInflater inflater) {
        total.clear();
        total1.clear();
        mCart = data;
        mContext = context;
        mLayoutInflater = inflater;
        mCbean = mCart.iterator();
        while (mCbean.hasNext()) {
            DataBean db = (DataBean) mCbean.next();
            cartList.add(db);
        }
        getTotalPrice();
    }

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

    @Override
    public Object getItem(int arg0) {

        return null;
    }

    @Override
    public long getItemId(int arg0) {

        return 0;
    }

    int count = 0;

    @Override
    public View getView(int position, View arg1, ViewGroup arg2) {
        final DataBean dbObj = cartList.get(position);
        final View v = mLayoutInflater.inflate(R.layout.cartitems, null);
        ImageView img = (ImageView) v.findViewById(R.id.imgView);
        int im = mContext.getResources().getIdentifier(dbObj.getImgpath(),
                "raw", mContext.getPackageName());
        img.setBackgroundResource(im);
        final TextView tv = (TextView) v.findViewById(R.id.tvPrice);
        tv.setText(dbObj.getPrice());
        final EditText etQuan = (EditText) v.findViewById(R.id.etQuantity);
        final int pos = position;
        final TextView brprice = (TextView) v.findViewById(R.id.tvTotal);
        brprice.setText(dbObj.getPrice());
        total.put(position, Double.parseDouble(dbObj.getPrice()));
        pr = pr + Double.parseDouble(brprice.getText().toString());
        mPosition = position;
        if (count != 0) {
            try {
                if (count != 0) {
                    String st = mQuantity.get(pos);
                    if (st.length() != 0)
                        etQuan.setText(st);
                    Double price = mPrice.get(pos);
                    if (price != null)
                        brprice.setText(price + "");

                }
            } catch (NullPointerException e) {

            }

        }

        etQuan.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {

                int quan;
                try {
                    mQuantity.put(pos, etQuan.getText().toString());
                    quan = Integer.parseInt(etQuan.getText().toString());
                } catch (NumberFormatException e) {
                    quan = 1;
                }
                double tprice = Double.parseDouble(dbObj.getPrice());
                brprice.setText("" + (tprice * quan));

                total.put(pos, (Double.parseDouble(dbObj.getPrice()) * quan));
                total1 = total;

                mPrice.put(pos, (tprice * quan));
                count++;
                price = quan + "";

            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {

            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            }
        });

        total2.put(position, Double.parseDouble(etQuan.getText().toString()));

        return v;
    }

    public static HashMap<Integer, Double> getTotalPrice() {

        if (total1.size() == 0)
            return total;
        else
            return total1;

    }

    public static HashMap<Integer, Double> getQunatity() {
        return total2;
    }

    public ArrayList<DataBean> getCartlist() {
        return cartList;
    }
}
Viewcart.java
----------------------
package gadgetstore.screens;

import gadgetstore.utils.CartAdapter;
import gadgetstore.utils.DataBean;
import gadgetstore.utils.StaticUtils;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ViewCart extends Activity implements OnClickListener {
    private ListView lv;
    private LayoutInflater mLayoutInflater = null;
    public ArrayList<DataBean> mCList;
    double totPrice;
    private Button mBtnCheckout, mBtnGt;
    private TextView mTvGt;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cart);
        lv = (ListView) findViewById(R.id.listViewCart);
        mLayoutInflater = getLayoutInflater();
        final CartAdapter lAdapter = new CartAdapter(getApplicationContext(),
                StaticUtils.sCart, mLayoutInflater);
        lv.setAdapter(lAdapter);
        lv.setCacheColorHint(0);
        mCList = lAdapter.getCartlist();
        mBtnCheckout = (Button) findViewById(R.id.btnChkOut);
        mBtnGt = (Button) findViewById(R.id.btnGT);
        mTvGt = (TextView) findViewById(R.id.tvGTotal);
        mBtnCheckout.setOnClickListener(this);
        mBtnGt.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v == mBtnCheckout) {
            startActivity(new Intent(ViewCart.this, PaypalScreen.class));
        } else if (v == mBtnGt) {

            HashMap<Integer, Double> price = new HashMap<Integer, Double>();
            price = CartAdapter.getTotalPrice();
            HashMap<Integer, Double> quantity = new HashMap<Integer, Double>();
            quantity = CartAdapter.getQunatity();

            int si = quantity.size();
            double d = 0.0;
            for (int j = 0; j < si; j++) {
                d = (quantity.get(j) * price.get(j)) + d;

            }

            mTvGt.setText("  " + d);

        }

    }

}