显示微调器中的选定行

时间:2014-04-17 16:54:21

标签: android sqlite android-spinner

我正在制作的应用程序在保存之前显示用户输入。其中一个微调器从数据库中获取数据。当我按下“查看”​​按钮时,我的应用程序在此行崩溃(有关NullPointException的内容)     final String estStatus = estType [row];

这是代码。

    private void displayReviewDetails() {

      // Get what the user entered

       Spinner estSpinner    = (Spinner) findViewById (R.id.est_spinner);
       Spinner spinner = (Spinner) findViewById (R.id.ratingSpinner);



       EditText mealCost  = (EditText) findViewById (R.id.editTextMealCost);
       EditText mealType  = (EditText) findViewById (R.id.editTextMealType);
       EditText comments = (EditText) findViewById (R.id.editTextComments);

       DatePicker rDate = (DatePicker) findViewById (R.id.datePicker1);

        // final so we can reference them in the anonymous inner class below

        int row = estSpinner.getSelectedItemPosition();
        final String estStatus = estType[row];

        int row1 = spinner.getSelectedItemPosition();
        final String ratingStatus = estRating[row1];

        final String strMealCost = mealCost.getText().toString();
        final String strMealType = mealType.getText().toString();
        final String strComments = comments.getText().toString();

        final String rateDate = rDate.getDayOfMonth() + "/"
        + (rDate.getMonth() + 1) + "/" + rDate.getYear();

        // Create and display the Alert dialog
        new AlertDialog.Builder(this)
        .setTitle("Details entered")
        .setMessage(
        "\n " + estStatus      + 
        "\n " + ratingStatus   + 
        "\n " + strMealCost    +
        "\n " + strMealType    + 
        "\n " + strComments    +
        "\n " + rateDate   )
        .setNeutralButton("Back",
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        // do nothing - it               will just close when clicked
        }
        })

        .setPositiveButton("Save",
           new DialogInterface.OnClickListener() {

           @Override
           public void onClick(DialogInterface dialog,  int which) {
                // save the details entered if "Save" button clicked
                saveReviews(estStatus, ratingStatus, strMealCost, strMealType,
                strComments, rateDate);
            }
        }).show();

1 个答案:

答案 0 :(得分:0)

您还可以使用getSelectedItem()。toString();