baidu_19694879
2016-03-29 07:25
采纳率: 50%
浏览 2.9k

android 点击动态添加view组成的listView的item时,显示出问题

android  listview中的item是动态添加的view, 点击item内的其中一个view时,显示的永远是页面上显示出来的的最后一个item的最后一个view中的值

List carLists = ci.getCarLists();
for (CarModle cm : carLists) {
typeSeries = cm.getTypeSeries();
typeName = cm.getTypeName();
LinearLayout layout = new LinearLayout(mActivity);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(params);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setPadding(50, 20, 20, 20);
TextView tv_typeSeries = new TextView(mActivity);
tv_typeSeries.setText(typeSeries);
TextView tv_typeName = new TextView(mActivity);
tv_typeName.setText(typeName);
tv_typeName.setLeft(20);
layout.addView(tv_typeSeries, params);
layout.addView(tv_typeName, params);
holder.layout_carInfo.addView(layout, params);
}

    holder.layout_carInfo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(mActivity, typeSeries + typeName, Toast.LENGTH_SHORT).show();
        }
    });

4条回答 默认 最新

相关推荐 更多相似问题