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();
}
});
已解決,謝謝各位,,,,,