0
我正在動態創建一個表。我正在使用另一個佈局文件膨脹行。 但這些動態行的onclick事件僅在第二次後觸發。 請協助。onclick僅在第二次調用動態充氣行後纔會調用android
private void populateRouteDetails(){
TableRow row;
View[] lArray = new View[24];
View lView = null;
LayoutParams lLayoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
for (int current = 0; current < 24; current++) {
row = new TableRow(this);
row.setPadding(0, 1, 0, 1);
LayoutInflater inflator = LayoutInflater.from(getBaseContext());
// inflate child
View item = inflator.inflate(R.layout.linear_row, null);
lArray[current] = item;
item.setPadding(0, 15, 0, 15);
row.addView(item);
row.setGravity(Gravity.CENTER_HORIZONTAL);
busRoute.addView(row, lLayoutParams);
lView = new View(this);
lView.setBackgroundColor(0xFF00FF00);
busRoute.addView(lView,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 1));
}
for(int lCount = 0;lCount<lArray.length;lCount++){
View lRow = lArray[lCount];
lRow.setClickable(true);
lRow.setFocusable(true);
lRow.setFocusableInTouchMode(true);
lRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View pView) {
Toast.makeText(BusDetails.this, "Hello",Toast.LENGTH_SHORT).show();
}
});
}
}