notifyDataSetChanged没有更新我的微调器

时间:2012-09-03 19:49:37

标签: android android-listview android-spinner android-adapter

我有两个带有两个不同适配器(adapteradapter2)的微调器。根据我选择的第一个适配器(adapter),我填充了第二个微调器(adapter2)。更改了第一个微调器中的数据后,我调用了adapter2.notifyDataSetChanged();,但这并没有更新我的第二个微调器。有什么想法吗?

更新:如果我调用新的适配器并按如下方式设置它正在更新:

adapter2 = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, objectList);
playerSpinner.setAdapter(adapter2);

但我认为这不是正确的做法....

ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, sDefaultPositions);
positionSpinner.setAdapter(adapter);

adapter2 = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, objectList);
playerSpinner.setAdapter(adapter2);

positionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View arg1, int pos, long arg3)
    {
        changeSpinnerView(parent.getItemAtPosition(pos).toString());
        Log.i("YourTeam", "ItemSlected"+objectList.toString());
        adapter2.notifyDataSetChanged();
    }
});



    private void changeSpinnerView(String position)
{
    objectList = getResults(playerkey);
    Collections.sort(objectList);

}

public ArrayList<String> getResults(int key)
{
    BLLPlayer playerdatasource = new BLLPlayer(this);
    playerdatasource.open();

    ArrayList<PlayerBean> resultList = new ArrayList<PlayerBean>();

    resultList = (ArrayList<PlayerBean>) playerdatasource.getAllFunctionList(key);

    playerdatasource.close();

    return getPlayerName(resultList);
}

private ArrayList<String> getPlayerName(ArrayList<PlayerBean> resultList)
{
    ArrayList<String> nameList = new ArrayList<String>();

    for (int iIndex = 0; iIndex < resultList.size(); iIndex++)
    {
        String beanName = resultList.get(iIndex).getName();

        if (beanName.equals("1"))
        {
            beanName = "";
        }
        else
        {
            nameList.add(beanName);
        }
    }

    return nameList;

}

0 个答案:

没有答案