我正在尝试使用相对布局添加不同的视图。添加了edittext和微调器,但列表视图未显示。另外,我没有使用xmls进行布局
public class CustomView extends LinearLayout {
Context rContext;
private String rTitle;
private Spinner rSpinner;
private EditText rInput;
private ListView rResultsList;
public CustomView(Context context) {
super(context);
rContext = context;
}
public CustomView(Context context, AttributeSet attrs, int theme) {
super(context, attrs, theme);
}
public void initialize(String title) {
rTitle = title;
rInput = new EditText(rContext);
rInput.setId(1);
rSpinner = new Spinner(rContext);
rSpinner.setId(2);
rResultsList = new ListView(rContext);
rResultsList.setId(3);
rInput.setText("1");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(rContext, R.layout.result_item, R.id.result_item, new String[] { "this", "that" });
rResultsList.setAdapter(adapter);
addViews();
}
@Override
public String toString() {
return rTitle;
}
private void addViews() {
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(ConvertoActivity.APP_WIDTH / 2, 100);
relativeParams.addRule(RelativeLayout.RIGHT_OF, rInput.getId());
RelativeLayout.LayoutParams relativeParams2 = new RelativeLayout.LayoutParams(ConvertoActivity.APP_WIDTH / 2, 100);
relativeParams.addRule(RelativeLayout.LEFT_OF, rSpinner.getId());
RelativeLayout.LayoutParams relativeParams3 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
relativeParams.addRule(RelativeLayout.BELOW, rInput.getId());
this.addView(rInput, relativeParams2);
this.addView(rSpinner, relativeParams);
this.addView(rResultsList, relativeParams3);
}
}