Android应用程序中的两个微调器

时间:2011-06-30 13:11:35

标签: android database sqlite spinner

我的旋转器有问题,

我的应用程序中的

是两个从数据库中获取数据的微调器,

当我从第一个微调器中选择一个选项时,我想从第二个微调器中删除此选项, 并添加我从第二个微调器移到第一个微调器的选项,反之亦然。

我该怎么做?

这是我现在的代码:

public void showScoresCalculator() {
    setContentView(R.layout.scores_calculator);

    Typeface font = Typeface.createFromAsset(getAssets(),"fonts/HelveticaProCn.ttf");

    TextView txt = (TextView) findViewById(R.id.txt);
    txt.setTypeface(font);

    TextView team = (TextView) findViewById(R.id.choose_team);
    team.setTypeface(font);     

    TextView group = (TextView) findViewById(R.id.choose_group);
    group.setTypeface(font);    

    TextView title = (TextView) findViewById(R.id.textView1);
    title.setTypeface(font);        

    TextView title2 = (TextView) findViewById(R.id.textView2);
    title2.setTypeface(font);   

    final Spinner sp = (Spinner) findViewById(R.id.spinner3);
    final Spinner sp1 = (Spinner) findViewById(R.id.spinner4);

    final DataBaseHelper.MyData[] items = this.dh.getTeamsNameAndIDs("38");
    final DataBaseHelper.MyData d = items[(int) sp.getSelectedItemId()];

    final DataBaseHelper.MyData[] items2 = this.dh
            .getTeamsNameAndIDs("47");
    final DataBaseHelper.MyData d1 = items2[(int) sp1.getSelectedItemId()];

    final ArrayAdapter<DataBaseHelper.MyData> adapter = new ArrayAdapter<DataBaseHelper.MyData>(
            this, android.R.layout.simple_spinner_item,
            this.dh.getTeamsNameAndIDs("38"));

    final ArrayAdapter<DataBaseHelper.MyData> adapter1 = new ArrayAdapter<DataBaseHelper.MyData>(
            this, android.R.layout.simple_spinner_item,
            this.dh.getTeamsNameAndIDs("47"));

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(adapter);
    sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            DataBaseHelper.MyData d = items2[(int) sp1.getSelectedItemId()];
            DataBaseHelper.MyData d1 = items[position];
            home = d.getValue();
            away = d1.getValue();
            if(Integer.valueOf(home.toString()) ==  Integer.valueOf(away.toString())) {
                Toast.makeText(getApplicationContext(), "Nie możesz wybrać dwóch tych samych drużyn.", Toast.LENGTH_SHORT).show();
            }else {
                showChart(d1.getValue(), d.getValue(), d1.getSpinnerText(), d.getSpinnerText(), "REMIS");
            }
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp1.setAdapter(adapter1);
    sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {

            DataBaseHelper.MyData d = items[(int) sp.getSelectedItemId()];
            DataBaseHelper.MyData d1 = items2[position];

            home = d.getValue();
            away = d1.getValue();

            if(Integer.valueOf(home.toString()) ==  Integer.valueOf(away.toString())) {
                Toast.makeText(getApplicationContext(), "Nie możesz wybrać dwóch tych samych drużyn.", Toast.LENGTH_SHORT).show();
            }else {
                showChart(d.getValue(), d1.getValue(), d.getSpinnerText(), d1.getSpinnerText(), "REMIS");
            }

        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final Button next = (Button) findViewById(R.id.next);
    final Button prev = (Button) findViewById(R.id.prev);

    next.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            showNewsPage();
        }
    });

    prev.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            showGroupCalculator();
        }
    });
    Page = true;
}

请帮帮我! :)

1 个答案:

答案 0 :(得分:1)

通过从列表中删除所选数据来更新适配器。使用处理程序概念更新适配器。

通过setAdapter()在Spinner上设置一个新适配器。或者,如果它是ArrayAdapter,请使用add(),insert()和remove()来修改数据。或者,如果它是CursorAdapter,请重新查询()以获取新数据。