微调器设置项目选定侦听器不起作用



>我有一个微调器,我可以从我的数据库中动态放置其项目,但问题是我无法知道方法setOnItemSelectedListener选择了哪个项目

这是我的java代码:

public class Choix extends Activity {
JSONArray ja1 = null;
List<String> list = new ArrayList<String>();
ArrayAdapter<String> dataAdapter;
Spinner spinner;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choix_espace); 
    spinner = (Spinner) findViewById(R.id.spinner); 
    liste_ecoles k = new liste_ecoles();
    k.execute();
  dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
        // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), ""+arg2, Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    }
private class liste_ecoles extends AsyncTask<String, Integer, Object> {
    String ch1="";
    @Override
    protected Object doInBackground(String... params) {
        JSONArray ja = null;

        try {
            URL twitter = new URL("...");
            URLConnection tc = twitter.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                ja = new JSONArray(line);
            }
        } catch (Exception e) {
        }
        return ja;
    }
    @Override
    protected void onPostExecute(Object resultat) {
        JSONArray ja = (JSONArray) resultat;
        if (resultat != null) {
            try {
                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo1 = null;
                    jo1 = ja.getJSONObject(i);
                    ch1 = jo1.getString("nom_ecole"); 
                    list.add(ch1);

                }

        }
        catch (Exception e) {
            }
        }
        }
        }   
    }

那么有人可以帮助我吗?

我解决了我的问题;我刚刚添加了" dataAdapter.notifyDataSetChanged(); 在我的微调器上添加项目后

相关内容

  • 没有找到相关文章

最新更新