Android 指定的子级已具有表布局中的父级
我想每1列设置1个图像,但错误是指定的子级已经有父级。必须首先对子级的父级调用removeView()。你能给我一个简单的解释吗。我该怎么办 这是我的密码Android 指定的子级已具有表布局中的父级,android,runtime-error,parent-child,android-tablelayout,Android,Runtime Error,Parent Child,Android Tablelayout,我想每1列设置1个图像,但错误是指定的子级已经有父级。必须首先对子级的父级调用removeView()。你能给我一个简单的解释吗。我该怎么办 这是我的密码 public class MybookActivity extends Activity{ private BooksDB db; private Context context; private HashMap< String, ArrayList<String>> hm; @Override protecte
public class MybookActivity extends Activity{
private BooksDB db;
private Context context;
private HashMap< String, ArrayList<String>> hm;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_mybook_sub2);
ArrayList<String> list_bokID = new ArrayList<String>();
ArrayList<String> list_title = new ArrayList<String>();
ArrayList<String> list_theme = new ArrayList<String>();
hm = new HashMap<String, ArrayList<String>>();
context = this;
db = new BooksDB(context);
hm = db.getBookTheme();
if(hm.isEmpty() == true){
System.out.println("NO data");
}else{
System.out.println("have data");
list_bokID = hm.get("bokID");
for (String bokID : list_bokID){
System.out.println(bokID);
}
list_title = hm.get("title");
for (String title : list_title) {
System.out.println(title);
}
list_theme = hm.get("theme");
for (String themePath : list_theme) {
System.out.println(themePath);
}
}
int Theme_size = list_theme.size();
//new
int numRow = Theme_size / 2;
int numCol = 5;
TableLayout tblLayout = (TableLayout) findViewById(R.id.tblLayout);
for(int i = 0; i < numRow; i++) {
HorizontalScrollView HSV = new HorizontalScrollView(this);
HSV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TableRow tblRow = new TableRow(this);
tblRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tblRow.setBackgroundResource(R.drawable.newshell);
for(int j = 0; j < numCol; j++) {
ImageView imageView = new ImageView(this);
for (String string : list_theme) {
int res_id = getResources().getIdentifier(string, "drawable", getPackageName());
imageView.setImageResource(res_id);
tblRow.addView(imageView,j);
}
}
HSV.addView(tblRow);
tblLayout.addView(HSV, i);
}
}
}
公共类MybookActivity扩展活动{
私人书店数据库;
私人语境;
私有HashMaphm;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.layout\u mybook\u sub2);
ArrayList_bokID=新的ArrayList();
ArrayList_title=新建ArrayList();
ArrayList_theme=新建ArrayList();
hm=新的HashMap();
上下文=这个;
db=新的BooksDB(上下文);
hm=db.getBookTheme();
if(hm.isEmpty()==true){
System.out.println(“无数据”);
}否则{
System.out.println(“有数据”);
list_bokID=hm.get(“bokID”);
用于(字符串bokID:list\u bokID){
系统输出打印LN(bokID);
}
list_title=hm.get(“title”);
用于(字符串标题:列表标题){
系统输出打印项次(标题);
}
list_theme=hm.get(“theme”);
for(字符串主题部分:列表主题){
System.out.println(themePath);
}
}
int Theme_size=list_Theme.size();
//新的
int numRow=主题大小/2;
int numCol=5;
TableLayout tblLayout=(TableLayout)findviewbyd(R.id.tblLayout);
for(int i=0;i
谢谢您需要添加的每个图像视图(以及添加到视图组的任何视图)的新实例 将实例创建移动到for内部循环中:
for (String string : list_theme) {
ImageView imageView = new ImageView(this);
int res_id = getResources().getIdentifier(string, "drawable", getPackageName());
imageView.setImageResource(res_id);
tblRow.addView(imageView,j);
}
把这段xml代码也展示给爱斯基摩人看。但是我想每列设置一个imageview,但是现在每列设置一个imageview。为什么?我不明白你的意思。