How to convert EditText value into Integer

I want to convert the value of EditText into an integer so I can use the integer value to do the calculation. But when I use parseInt() method to do it, my eclipse simulator will corrupt. What I can do to exactly convert value I entered in alertdialog edittext into integer value?

    tv = (TextView) findViewById(R.id.tv3);
                btn = (Button) findViewById(R.id.bt1);

                final ListView listview = (ListView) findViewById(R.id.listView);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, listItems);
                listview.setAdapter(adapter);
                btn.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        Intent i = new Intent(MainActivity.this,Income.class);
                        startActivity(i);
                    }
                });

                final EditText et = new EditText(this);

                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("Budget Category");
                builder.setMessage("Please enter your amount");
                et.setInputType(InputType.TYPE_CLASS_NUMBER);
                et.setHint("RM0");
                builder.setView(et);

                builder.setCancelable(false);
                builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(), et.getText(),
                                Toast.LENGTH_SHORT).show();
                        tv.setText(v);
                        // String value= et.getText().toString();
                        // int cvalue=Integer.parseInt(value);
                        // totalbudget = totalbudget + cvalue;
                    }
                });
                builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                final AlertDialog alert = builder.create();

                listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // TODO Auto-generated method stub
                        String s = listview.getItemAtPosition(position).toString();
                        if (s.equals("Food")) {
                            food = Integer.parseInt(et.getText().toString());
                        } else {
                            correctCategory = false;
                        }
                        alert.show();
                    }
                });
            }
        }

I expect it can convert String into integer value

Leave a Reply

avatar
  Subscribe  
Notify of