在Java:Android中删除String数组的第一个元素



假设我有这个字符串数组"{Unclaimed", "Lost/Stolen", "Damaged/Defective", "Pawned", "Not Turned Over", "Others"},我想删除第一个是Unclaimed,如果单击aat_distribution_status,它会删除,有没有删除它?我试过Reasons = Reasons.Skip(1).ToArray(),但不起作用

我的示例代码

AutoCompleteTextView aat_reason_not_presented;
aat_reason_not_presented = findViewById(R.id.aat_reason_not_presented);
String[] Reasons = new String[]{"Unclaimed", "Lost/Stolen", "Damaged/Defective", "Pawned", "Not Turned Over", "Others"};
ArrayAdapter<String> adapterYesNo = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item, Reasons);
adapterYesNo.setDropDownViewResource(simple_spinner_dropdown_item);
aat_reason_not_presented.setAdapter(adapterYesNo);
aat_distribution_status.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int pos, long id) {
Reasons = Reasons.Skip(1).ToArray() //Trying to remove first element of reasons but it didn't work
}
});

您可以像一样使用Arrays.copyOfRange(T[], int, int)

Reasons = Arrays.copyOfRange(Reasons, 1, Reasons.length);

此外,Java变量名按照约定以小写字母开头。最后,我怀疑Reasons必须是有效的final,才能在这样的内部类中使用它。所以我怀疑这是否会起作用。

相关内容

  • 没有找到相关文章

最新更新