I have problem with my spinners,
in my app are two spinners which gets data from database,
when i choose one option from first spinner, i want to remove this option from second spinner, and add option which i removed from second spinner to first spinner and vice versa.
How can i do that ?
This is my present code:
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); 开发者_StackOverflow中文版
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;
}
Please, help me ! :)
Update the adapter by removing the selected data from the list. Use Handler concept to update adapter.
Set a new adapter on the Spinner via setAdapter(). Or, if it is an ArrayAdapter, use add(), insert(), and remove() to modify the data. Or, if it is a CursorAdapter, requery() it to get fresh data.
精彩评论