我正在编写一个购物车应用,并允许用户将商品添加到购物车 Activity ,在购物车商品列表中,我使用3 个 TextView 作为数值(即:项目成本、数量、总计),这些值来自 ProductInformationActivity.java,现在我希望允许用户更新任何项目通过单击该特定项目仍在购物车 Activity 中,我想在 ProductInformationActivity.java 中打开该项目,其中包含现有详细信息,例如:用户之前输入的数量(例如:我们在购物车应用程序中看到),为此,我在我的购物车适配器中使用了以下代码....
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);
}
});
最佳答案
您可以做两件事:
首先,在您的 EditText 字段中只允许使用数字数据。
其次,通过简单检查确保您的 EditText
中没有空值。
if(text_cost_code.getText().length() > 0) { try{ itemamount = Double.parseDouble(text_cost_code.getText().toString()); catch(NumberFormatException e) { } }
确保您已在 TextView
中将 inputType 定义为 number
或 numberSigned
android:inputType="numberSigned"
已编辑:
尝试从 ProductInformationActivity
中的 Intent
获取字符串,如下所示:
String myItemValue = getIntent().getStringExtra("Item");
关于android - 单击 CartActivity 中的 ListView 项目行时获取不包含现有产品信息的空白 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16312970/