Getting an empty action not with existing product information when you click on a list box list item in CartActivity

I am writing an application for a basket and letting the user add items to Activity Activity , in the basket list I use 3 text fields for a numerical value (that is: product price, quantity, amount) and these values come from ProductInformationActivity.java , now I want to allow the user to update any element that is still in Activity Activity by clicking on this specific element, I want to open this element in ProductInformationActivity.java with existing data, such as: which Qty user entered earlier (for example: we see in Cart applications), so that To do this, I use the code below in my Cart Adapter ....

public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View vi = convertView; if (convertView == null) vi = inflater.inflate(R.layout.listrow_cart, null); vi.setClickable(true); vi.setFocusable(true); vi.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { HashMap<String, String> item = Constant.wishProducts.get(position); Log.d("CartAdapter", "onClick :: " + item); Intent myIntent = new Intent (activity, com.era.restaurant.versionoct.menu.ProductInformationActivity.class); Log.d("CartAdapter", "Intent :: " + myIntent); myIntent.putExtra("Item", item); activity.startActivity(myIntent); } }); 
+4
source share
2 answers

Two things you can do:

First, only allow numeric data in your EditText field.

Secondly, make sure you don't have a null value in EditText with a simple check.

  if(text_cost_code.getText().length() > 0) { try{ itemamount = Double.parseDouble(text_cost_code.getText().toString()); catch(NumberFormatException e) { } } 

Make sure you define inputType as number or numberSigned in android:inputType="numberSigned" TextView android:inputType="numberSigned"

Edition:

Try to get a string from Intent in your ProductInformationActivity , as shown below:

  String myItemValue = getIntent().getStringExtra("Item"); 
+2
source

Edit:

You send a HashMap<String,String> as an extra when you click on a list item.

You should get an additional HashMap, and then get information about it. like this

  HashMap<String,String> items=new HashMap<String,String>(); if (getIntent().getSerializableExtra("item") != null) items = (HashMap<String, String>) getIntent().getSerializableExtra("item"); String title = items.get(KEY_TITLE); String description = items.get(KEY_DESCRIPTION); String thumb_url = items.get(KEY_THUMB_URL); String cost = items.get(KEY_COST); String total =items.get(KEY_TOTAL); 

this

  itemamount = Double.parseDouble(text_cost_code.getText().toString()); 

throws an Exception because either text_cost_code.getText().toString() not Number , or it is empty

You need to make sure that it contains Number and is not empty.

then put this code in try catch , if Excluded is caught, then change the value to 0

 try{ itemamount = Double.parseDouble(text_cost_code.getText().toString().trim()); } catch(NumberFormatException e) { itemamount=0; } 
+1
source

All Articles