我正在尝试以编程方式在编程语言中设置listView项的行高(艺术作品的java包装器) 在下面的代码中,我尝试用注释行来做到这一点。但它给出了错误; 任何的想法?
类型不匹配:无法从ViewGroup.LayoutParams转换为 AbsListView.LayoutParams
ListView self;
public void init() {
setBackgroundColor(Color.BLUE);
setAlpha(255);
self = this;
layout = new RelativeLayout(parent.getActivity());
if (title != "") {
TextView tv = new TextView(parent.getActivity());
tv.setText(title);
setHeaderDividersEnabled(true);
addHeaderView(tv);
}
setAdapter(adapter);
setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> p, View view, int position, long id) {
selection = adapter.getItem(int(id)).toString();
layout.removeAllViewsInLayout();
try {
parentCallback.invoke(parent, new Object[] { self });
}
catch (Exception ex) {
}
self.setVisibility(View.GONE);
((ViewManager) self.getParent()).removeView(self);
parent.getActivity().runOnUiThread(new Runnable() {
public void run() {
layout.removeAllViews();
layout.setVisibility(View.GONE);
}
}
);
}
}
);
try {
parentCallback = parent.getClass().getMethod("onSelectionKListSelection", new Class[] { SelectionKList.class });
PApplet.println("Found onSelectionKListSelection...");
}
catch (NoSuchMethodException e) {
}
parent.getActivity().runOnUiThread(new Runnable() {
@SuppressWarnings("deprecation")
public void run() {
parent.getActivity().addContentView(self, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) self.getLayoutParams();
layoutParams.setMargins(150, 150, 150, 150);
self.setDividerHeight(5);
// LayoutParams params = self.getLayoutParams(); // Set the height of the Item Vie
// params.height = 40;
// self.setLayoutParams(params);
}
}
);
}