我制作了一個自定義比較器來按字母順序?qū)ψ远x ArrayList 中的對象進行排序。列表中的項目有一個 OnItemClickListener。我的應用程序是多語言的。當我在設(shè)置中切換語言時,項目會改變它們的位置。因此, 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
提交
取消