在微调器中,无论何时我选择一个项目,它都应该是不活动的,或者阻止用户再次选择,并且每当用户删除所选项目时,该项目应该是活动的,用户可以再次选择。列表中的项目应动态添加和删除。谁能告诉我该怎么做? 任何帮助将不胜感激。如果您无法理解问题,请在此处评论
我用于添加新项目并删除该项目的代码,如下所示:
public void add_click()
{
add.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
spin = findViewById(R.id.spinnerLayout);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addview = (layoutInflater).inflate(R.layout.spinner, null);
addview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup
.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
game_name_Spinner = addview.findViewById(R.id.gamename);
player_level_Spinner = addview.findViewById(R.id.level);
remove = addview.findViewById(R.id.delete_button);
s_game = name1.getSelectedItem().toString();
s_level = level1.getSelectedItem().toString();
game_name_Spinner.setText(s_game);
player_level_Spinner.setText(s_level);
remove.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String last_removed;
((LinearLayout) addview.getParent()).removeView(addview);
gamename.addAll(removed_item);
adap1 = new ArrayAdapter<String>(PlayerProfile.this, android.R.layout
.simple_spinner_dropdown_item, gamename);
name1.setAdapter(adap1);
adap1.notifyDataSetChanged();
}
});
if (name1.getSelectedItemPosition()>0)
{
int count = removed_item.size();
for (int i = 0; i<=count; i++)
{
game_name_Spinner.setId(i);
}
idl = game_name_Spinner.getId();
game_removed = name1.getSelectedItem().toString();
removed_item.add(game_removed);
LinkedHashSet<String> hashSet = new LinkedHashSet<String>();
hashSet.add(game_removed);
removed_item.clear();
removed_item.add(game_removed);
adap1.remove(name1.getSelectedItem().toString());
}
container = findViewById(R.id.container);
container.addView(addview);
name1.setSelection(0);
level1.setSelection(0);
}
});
}