MainLayout=(LinearLayout) getActivity().findViewById(R.id.LinLaySub);
for(int k=0;k<Dist_cat.length;k++) {
Cursor c = db.getQueryResult("select * from prod_mas where sub_name='" + Dist_catname[k] + "'");
for (int i = 0; i < c.getCount(); i++) {
c.moveToFirst();
ChildLayout=new LinearLayout(getActivity());
ChildLayout.setWeightSum(100);
ChildLayout.setOrientation(LinearLayout.HORIZONTAL);
ChildLayout.setBackgroundColor(getResources().getColor(R.color.sublay));
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
ChildLayout.setId(i);
edit_phy = new EditText(getActivity());
edit_phyAll.add(edit_phy);
edit_phy.setBackgroundResource(R.color.black);
edit_phy.setId(+i + 1);
edit_phy.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ChildLayout.addView(edit_phy);
edit_trn = new EditText(getActivity());
edit_trnAll.add(edit_trn);
edit_trn.setBackgroundResource(R.color.black);
edit_trn.setId(+i + 2);
edit_trn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ChildLayout.addView(edit_trn);
MainLayout.onViewAdded(ChildLayout);
c.moveToNext();
}
}
我正在尝试以编程方式添加一些 ui 元素,但出现错误,即,
java.lang.IllegalAccessError: tried to access method android.widget.LinearLayout.onViewAdded:
谁能帮我解决一下
最佳答案
换行
MainLayout.onViewAdded(ChildLayout);
到
MainLayout.addView(ChildLayout);
关于java.lang.IllegalAccessError : tried to access method android. 部件.LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35500604/