一个数组的TextView变量没有得到识别



我尝试创建一个textviews变量的数组,如下所示,但是eclipse用红色曲线强调了存储在数组中的textview变量。我不知道为什么?

Java_code:

int [] viewsRefsIds = {R.id.reportLocNameValue, R.id.reportLocLatValue, R.id.reportLocLngValue, R.id.reportTimeValue,
                    R.id.reportDateValue, R.id.reportImgTitleValue, R.id.reportImgPathValue
            };
            TextView [] viewsVariables = {reportAlertDialogLocName, reportAlertDialogLocLat, reportAlertDialogLocLng, 
                    reportAlertDialogTime, reportAlertDialogDate, reportAlertDialogImgTitle, reportAlertDialogImgPath
            };
            TextView reportAlertDialogMSG = (TextView) reportAlertDialog.findViewById(R.id.reportDialogMessageID);              
            reportAlertDialogMSG.setText(REPORT_ALERT_DIALOG_MSG);
            for (int i=0; i<bundleVals.length; i++) {
                viewsVariables[i] = (TextView) reportAlertDialog.findViewById(viewsRefsIds[i]);
            }

对我来说这很有效…

int[] viewsRefsIds = {R.id.text,...};
TextView[] viewsVariables = new TextView[viewsRefsIds.length];
for (int i=0; i<viewsRefsIds.length; i++) {
    viewsVariables[i] = (TextView)findViewById(viewsRefsIds[i]);
}

也许"clean"会有帮助:)

最新更新