我有很多国家。在执行更新功能时,我希望数据库中保存的任何数据都应保存在EditText和微调器中。对于微调器,我得到一个错误资源找不到。
我这样做是为了将数据库中的默认选择数据设置为微调器,

// local country is added in arraylist

   ArrayList<String> arraylist_country = new ArrayList<String>();
    arraylist_country.add(memberPersonalDetailsScreenActivityController.getMemberMasterData().get(0).getL_country().toString());

       for(int i=0 ; i<length ; i++){
          if(select_member_id == member_id[i]){
             spinner_country.setSelection(arraylist_country.indexOf(local_country[i]));
          }

是否有其他解决方案可以将默认选择数据设置为微调器?

最佳答案

我已经解决了我的问题。我已经在这里给出了我的代码,这样我们就可以从数据库中为特定的行设置defult selection为spinner。
在OnEng-中

    //Declared spinner and used ArrayAdapter

    spinner_country = (Spinner) findViewById(R.id.spinner_country_susa);
    spinner_country.setOnItemSelectedListener(this);

    country_adapter = ArrayAdapter.createFromResource(this, R.array.country_array, android.R.layout.simple_spinner_item);
    country_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner_country.setAdapter(country_adapter);

在编辑()中
//user defined function called in onCreate()
    String[] local_country = memberPersonalDetailsScreenActivityController.getMemberMasterData().get(0).getL_country();
    for(int i=0 ; i<length ; i++){
        if(select_member_id == member_id[i]){
             spinner_country.setSelection(country_adapter.getPosition(local_country[i]));
        }
    }

07-24 09:49
查看更多