1

我有 2 个带有两个不同适配器(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;

}
4

0 回答 0