0

该活动动态地构建一个表。我想为所有行添加一个 OnClickListener。我正在这样做:

TableLayout table = (TableLayout) findViewById(R.id.body);
for (final Document d : result) {
    TableRow row;
    if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
        row = (TableRow) LayoutInflater.from(
                LastDocumentsActivity.this).inflate(
                R.layout.last_documents_body_row_portrait, null);

        ((TextView) row.findViewById(R.id.date)).setText(d
                .getDate());
        ((TextView) row.findViewById(R.id.number)).setText(d
                .getNumber());
        ((TextView) row.findViewById(R.id.value_netto)).setText(d
                .getValueNetto().toString());
        ((TextView) row.findViewById(R.id.currency)).setText(d
                .getCurrency());

        table.addView(row);
    } else {
        row = (TableRow) LayoutInflater.from(
                LastDocumentsActivity.this).inflate(
                R.layout.last_documents_body_row_landscape, null);

        ((TextView) row.findViewById(R.id.number)).setText(d
                .getNumber());
        ((TextView) row.findViewById(R.id.date)).setText(d
                .getDate());
        ((TextView) row.findViewById(R.id.value_netto)).setText(d
                .getValueNetto().toString());
        ((TextView) row.findViewById(R.id.value_brutto)).setText(d
                .getValueBrutto().toString());
        ((TextView) row.findViewById(R.id.currency)).setText(d
                .getCurrency());
        ((TextView) row.findViewById(R.id.status)).setText(d
                .getStatus());
        ((TextView) row.findViewById(R.id.responsible_person))
                .setText(d.getPersonResponsible());
        ((TextView) row.findViewById(R.id.orderId)).setText(Integer
                .toString(d.getId()));

        table.addView(row);
    }
    row.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("info", "OnClickListener works.");
            Intent i = new Intent(LastDocumentsActivity.this,
                    DocumentDetailsActivity.class);
            i.putExtra("document_id", d.id);
            startActivity(i);
        }
    });
}

它在模拟器(3,2" QVGA (ADP2) (320x480:mdpi) Android 2.2)中完美运行,但在我的手机上没有。(华为 Ascend Y300,Android 4.1.1)屏幕看起来一样(除了从分辨率),只是 OnClickListener 不起作用。可能是什么原因,我该如何解决?

4

0 回答 0