Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
LinkBack Thread Tools
Old November 28th, 2012, 03:18 AM   #1 (permalink)
Thread Author (OP)
Join Date: Dec 2011
Location: chennai
Posts: 158
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default Add selected product to cart in android

I have developed one android list view app using xml parsing.this is done for my first page.

After i have to click any product from list means am getting the detailed product description in displayed on next activity.it is also done.

Here i have to implement one part.

the detailed order page have one button add to cart.here i have to click this button means the selected product is added on my cart.how can i implement this.please help me.

This is my first activity(list view using xml parsing):

public class CustomizedListView extends Activity {
// All static variables
static final String URL = "";
// XML node keys
static final String KEY_SONG = "Product"; // parent node
static final String KEY_ID = "productid";
static final String KEY_TITLE = "Name";
static final String KEY_ARTIST = "ProductURL";
static final String KEY_DURATION = "Price";
static final String KEY_THUMB_URL = "Image";

ListView list;
LazyAdapter adapter;

public void onCreate(Bundle savedInstanceState) {

ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(KEY_SONG);

// looping through all song nodes &lt;song&gt;
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key =&gt; value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

// adding HashList to ArrayList


// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);

// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

String title = ((TextView) view.findViewById(R.id.title)).getText().toString( );
String duration = ((TextView) view.findViewById(R.id.duration)).getText().toStri ng();
String artist = ((TextView) view.findViewById(R.id.artist)).getText().toString ();
String thumb_image = ((ImageView) view.findViewById(R.id.list_image)).getImageMatrix ().toString();

// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_DURATION, duration);
in.putExtra(KEY_ARTIST, artist);
in.putExtra(KEY_THUMB_URL, thumb_image);


This is detailed description activity:

public class SingleMenuItemActivity extends Activity {
Button cart;
// XML node keys
static final String KEY_TITLE = "Name";
static final String KEY_DURATION = "Price";
static final String KEY_ARTIST = "ProductURL";
static final String KEY_THUMB_URL = "Image";

public void onCreate(Bundle savedInstanceState) {

int productIndex = getIntent().getExtras().getInt(CustomizedListView. URL);

//final CustomizedListView selectedProduct = songsList.getInt(productIndex);
cart = (Button)findViewById(R.id.cart);
cart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

// getting intent data
Intent in = getIntent();

// Get XML values from previous intent
String title = in.getStringExtra(KEY_TITLE);
String duration = in.getStringExtra(KEY_DURATION);
String artist = in.getStringExtra(KEY_ARTIST);
final String thumb_image = in.getStringExtra(KEY_THUMB_URL);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCost = (TextView) findViewById(R.id.cost_label);
TextView lblDesc = (TextView) findViewById(R.id.description_label);
ImageView imgv = (ImageView) findViewById(R.id.image_label);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());

imageLoader.DisplayImage(thumb_image, imgv);

I have to add add to cart button in these 2nd activity.what condition i have to put here for selected product item is add to cart .please give me solution for some useful coding wise.please help me.

krishnaveni is offline  
Reply With Quote
sponsored links
Old November 29th, 2012, 05:26 PM   #2 (permalink)
Senior Member
jonbonazza's Avatar
Join Date: Jul 2010
Gender: Male
Posts: 1,935
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts

First of all, the datastore shouldn't exist locally. Doing this would create a HUGE security vulnerability, as well as allow for easy hacking. The datastore should be located remotely on a server somewhere, where the user would request the data from a remote web service and that web service would process this request and, if valid, push the requested data back to the client. The client would then receive the response and apply further processing.

Also, a relational database would be more appropriate here than XML.
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
android, cart, java, listview, shopping, xml parsing

Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 05:32 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.