AlertDialog没有刷新数据

时间:2017-05-09 17:57:28

标签: java android

public void setFileName(String inMake, String inModel) {
    //sets spinner to get year
    filename = filename.concat(inMake);
    filename = filename.concat(inModel);
    filename = filename.concat(".txt");

    spinner3 = (Spinner) findViewById(R.id.spinner3);

    BufferedReader reader;
    AssetManager assetManager = MainActivity.getContext().getAssets();
    List<String> testYears = new ArrayList<String>();
    try {
        InputStream istr = assetManager.open(filename);
        reader = new BufferedReader(new InputStreamReader(istr));
        String line;
        while((line = reader.readLine()) != null) {
            testYears.add(line);
        }
    }
    catch (IOException e){
        Log.e("message: ",e.getMessage());
    }

    AlertDialog.Builder yearDialog = new Builder(this);
    yearDialog.setTitle("Select Year");

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice, testYears);

    adapter.notifyDataSetChanged();
    yearDialog.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            year = Integer.parseInt(adapter.getItem(which));
            Toast.makeText(getApplicationContext(),
                    "Year : " + year, Toast.LENGTH_SHORT).show();
        }
    });
    AlertDialog alert = yearDialog.create();
    alert.show();
}

我正在尝试通过alertdialog检索用户选择。它用于arrayAdapter的数组基于函数的输入(字符串inmake,字符串inmodel),它是从活动外部传递的。这种方法似乎完美 - 但只是第一次。如果我向方法发送新的字符串信息,它不会在alertdialog中显示任何选项。

任何帮助都有很大的帮助。

0 个答案:

没有答案