这是我的类,它扩展了RelativeLayout并填充了一个线性布局:
public CageParameterConfigItem(CageParameterConfigActivity context,Cage cage, VariabiliCentralina item)
{
super(context);
mainActivity = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.cage_parameter_configurator_item, this, true);
currentVariabile = item;
fatherCage = cage;
nomeMisura = (TextView)findViewById(R.id.cage_parameter_config_item_sondaName);
abilitazione = (CheckBox)findViewById(R.id.cage_parameter_config_item_Abilitazione);
soglia1 = (EditText)findViewById(R.id.cage_parameter_config_item_soglia1);
isteresi1 = (EditText)findViewById(R.id.cage_parameter_config_item_isteresi1);
soglia2 = (EditText)findViewById(R.id.cage_parameter_config_item_soglia2);
isteresi2 = (EditText)findViewById(R.id.cage_parameter_config_item_isteresi2);
allarmeMin = (EditText)findViewById(R.id.cage_parameter_config_item_AllarmMin);
allarmeMax = (EditText)findViewById(R.id.cage_parameter_config_item_AllarmMax);
salinity = (EditText)findViewById(R.id.cage_parameter_config_item_salinity);
salinityText = (TextView)findViewById(R.id.cage_parameter_config_item_salinity_text);
if(!currentVariabile.hasCalibration())
{
salinity.setVisibility(View.INVISIBLE);
salinityText.setVisibility(View.INVISIBLE);
}
bindData();
}
protected void bindData()
{
nomeMisura.setText(VariabiliCentralina.TipoSondaToString(currentVariabile.tipoSonda,getContext()));
abilitazione.setChecked(currentVariabile.parametri.abilitazione);
soglia1.setText(String.format("%.1f", currentVariabile.parametri.soglia1));
soglia2.setText(String.format("%.1f", currentVariabile.parametri.soglia2));
isteresi1.setText(String.format("%.1f", currentVariabile.parametri.isteresi1));
isteresi2.setText(String.format("%.1f", currentVariabile.parametri.isteresi2));
allarmeMin.setText(String.format("%.1f", currentVariabile.parametri.allarmeMin));
allarmeMax.setText(String.format("%.1f", currentVariabile.parametri.allarmeMax));
salinity.setText(String.format("%d", currentVariabile.parametri.salinity));
}
这是来自主要活动类的填充线性布局的代码:
protected void populateGrid()
{
misureContainer.removeAllViews();
vMisureView.clear();
CageParameterConfigItem newView;
for( VariabiliCentralina item : currentCage.vMisure)
{
newView = new CageParameterConfigItem(this,currentCage, item);
misureContainer.addView(newView);
}
}
其中misureContainer是linearLayout。
在索尼体验上一切正常,但在Nexus 5上,当我在bind()函数上使用setText时,所有具有相同资源ID的textView都采用相同的值。我不明白为什么! 你能救我吗?