具有多个阵列的自定义适配器OnItemClick

时间:2014-04-07 19:28:41

标签: java android arraylist

public void populate(ArrayList<String> array, ArrayList<String> array2) {
            ListView showList = (ListView) findViewById(R.id.listView1);
            SchedAdapter shows = new SchedAdapter(getApplicationContext(),
                    R.layout.rowlayout, array, array2);
            showList.setAdapter(shows);
            showList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, final View view,
                        final int position, long id) {
                    final String selected = (String) parent
                            .getItemAtPosition(position);
                    Toast.makeText(getApplicationContext(), selected,
                            Toast.LENGTH_SHORT).show();
                }

            });
        }

Toast显示array2中的字符串,我希望它显示array中保存的字符串。我怎么能做到这一点?

1 个答案:

答案 0 :(得分:1)

 public void populate(ArrayList<String> array, ArrayList<String> array2) {
        ListView showList = (ListView) findViewById(R.id.listView1);
        SchedAdapter shows = new SchedAdapter(getApplicationContext(),
                R.layout.rowlayout, array, array2);
        showList.setAdapter(shows);
        showList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, final View view,
                    final int position, long id) {

               Toast.makeText(getApplicationContext(), array2.get(position),
                        Toast.LENGTH_SHORT).show();
               Toast.makeText(getApplicationContext(), array.get(position),
                         Toast.LENGTH_SHORT).show();
            }

        });
    }