Android 애플리케이션에 문제가 있습니다. 동적으로 TableLayout에 행을 추가하려고합니다. 상황 : 특정 단추를 클릭하면 행이 TableLayout에 추가되고 내부의 텍스트는 입력 된 내용에 따라 특정 EditText에 추가됩니다. 그보기는 이유,Android - 프로그래밍 방식으로 행을 추가하면 표시되지 않음
public class Rekenmodel extends Activity{
TableLayout landenTable;
Data context = Data.GetInstance();
String binnenUwRegio, selectedCountry, buitenUwRegio, naar085Bedrijfsnummers, naar088Bedrijfsnummers, naar0900Servicenummers, overigeGesprekken;
Button b_send, b_addCountry;
Spinner countries;
EditText et_landen_aantalGesprekken, et_landen_bedrag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kpn_rekenmodel);
landenTable = (TableLayout) findViewById(R.id.landenTable);
countries = (Spinner) findViewById(R.id.countries);
et_landen_aantalGesprekken = (EditText)this.findViewById(R.id.et_landen_aantalGesprekken);
et_landen_bedrag = (EditText)this.findViewById(R.id.et_landen_bedrag);
b_addCountry = (Button)this.findViewById(R.id.addCountryButton);
b_addCountry.setOnClickListener(addCountryButtonListener);
}
private OnClickListener addCountryButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
final TableRow tr = new TableRow(Rekenmodel.this);
TextView landKeuze = new TextView(Rekenmodel.this);
landKeuze.setText(countries.getSelectedItem().toString());
landKeuze.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.45f));
tr.addView(landKeuze);
Button delete = new Button(Rekenmodel.this);
delete.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.05f));
delete.setText("Delete");
delete.setTextSize(10f);
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
landenTable.removeView(tr);
}
});
tr.addView(delete);
TextView aantalGesprekken = new TextView(Rekenmodel.this);
aantalGesprekken.setText(et_landen_aantalGesprekken.getText().toString());
aantalGesprekken.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.15f));
tr.addView(aantalGesprekken);
TextView duur = new TextView(Rekenmodel.this);
duur.setText("Test duur");
duur.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.20f));
tr.addView(duur);
TextView bedrag = new TextView(Rekenmodel.this);
bedrag.setText(et_landen_bedrag.getText().toString());
bedrag.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.15f));
tr.addView(bedrag);
landenTable.addView(tr);
}
};
}
logcat과 관련된 사항은 무엇입니까? –
landenTable.invalidate()? – Simon
이 픽스를 적용하여이 문제를 해결했습니다. http://stackoverflow.com/questions/11963465/android-layoutparams-for-textview-makes-the-view-disappear-programatically – user2029070