ListView返回错误的列表和位置

时间:2018-03-08 13:28:12

标签: java android xml listview android-adapter

基本上我有2个ListViews;到达/离开,当您点击任一列表中的项目时,它将返回标题但是当我点击我的"离开" list它返回我的Arrivals列表中的元素,这是我的听众!任何帮助将不胜感激

这里是我设置每个列表的地方

    ListView DeparturesListView = (ListView)findViewById(R.id.Departures);
    ThreeHorizontalTextViewsAdapter threeHorizontalTextViewsAdapter1 = new ThreeHorizontalTextViewsAdapter(getApplicationContext(), R.layout.three_horizontal_textviews_layout, DeparturesList);
    DeparturesListView.setAdapter(threeHorizontalTextViewsAdapter1);
    ListView ArrivalsListView = (ListView)findViewById(R.id.Arrivals);
    ThreeHorizontalTextViewsAdapter threeHorizontalTextViewsAdapter2 = new ThreeHorizontalTextViewsAdapter(getApplicationContext(), R.layout.three_horizontal_textviews_layout, ArrivalsList);
    ArrivalsListView.setAdapter(threeHorizontalTextViewsAdapter2);

这些是我的听众

    ArrivalsListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
        {
            ThreeStrings temp2 = (ThreeStrings) ArrivalsListView.getAdapter().getItem(position);
            TrainService ArrivalTrain = temp2.getTrain();
            Log.d("templor", "ARRIVAL: "+ArrivalTrain.getOrigin().getLocationName().toString());
        }
    });
    DeparturesListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
        {

            ThreeStrings temp = (ThreeStrings) DeparturesListView.getAdapter().getItem(position);
            TrainService service = temp.getTrain();
            Log.d("templor", "DEPARTURE"+service.getOrigin().getLocationName().toString());
        }
    });

0 个答案:

没有答案