我制作了一个自定义比较器来按字母顺序对自定义 ArrayList 中的对象进行排序。列表中的项目有一个 OnItemClickListener。我的应用程序是多语言的。当我在设置中切换语言时,项目会改变它们的位置。因此, OnItemClickListener 失去了与索引中项目位置的匹配。如何链接项目的位置以在正确的位置维护点击侦听器?这是活动:public class ColorsCatalogue extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_colors_catalogue); final ArrayList<setTextViewCatalogue> arrayListCatalogo = new ArrayList<>(); arrayListCatalogo.add(new setTextViewCatalogue(getResources().getString(R.string.codice_arancione), getResources().getString(R.string.sfumature_di_arancione), getResources().getString(R.string.codice_arancione))); arrayListCatalogo.add(new setTextViewCatalogue(getResources().getString(R.string.codice_bianco), getResources().getString(R.string.sfumature_di_bianco), getResources().getString(R.string.codice_bianco))); arrayListCatalogo.add(new setTextViewCatalogue(getResources().getString(R.string.codice_blu), getResources().getString(R.string.sfumature_di_blu), getResources().getString(R.string.codice_blu))); Collections.sort(arrayListCatalogo, new AlphabeticalComparator()); setTextViewCatalogueAdapter adapter = new setTextViewCatalogueAdapter(this,arrayListCatalogo); ListView listView = findViewById(R.id.catalogueListView); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (i == 0) { Intent goToShadesOfOrange = new Intent(ColorsCatalogue.this, ShadesOfOrange.class); startActivity(goToShadesOfOrange); } } }); }}
添加回答
举报
0/150
提交
取消