刷新tableLayout [英] Refresh tableLayout

查看:139
本文介绍了刷新tableLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个tableLayout和我填充ImageView的[] []使用嵌套循环的布局。目前我想点击一个ImageView的和重新排列ImageView的[] []的数据,那么刷新屏幕,以反映重排。有没有办法做到这一点?显然,我不能调用setContentView不止一次。

编辑:你可以看到这是code为onclick事件。我的setContentView在onCreate事件原来TableLayout('TL'),不能在这里再次调用它。

 公共无效的onClick(视图v){
    // TODO自动生成方法存根
    开关(v.getId()){
    情况1:
        image_array = switchTile(image_array,2,1,0,0);
        Toast.makeText(这一点,1点击!,Toast.LENGTH_LONG).show();    }    tl.removeAllViewsInLayout();    的for(int i = 0; I<水平;我++){
        的TableRow new_tr =新的TableRow(本);
        new_tr.setLayoutParams(layout_image);        对于(INT J = 0; J<水平; J ++){
            new_tr.addView(image_array [I] [J]);
        }
        tl.addView(new_tr);
    }    tl.invalidate();}


解决方案

如果你想要做的就是四处移动的图像,你可以做对现有ImageViews setImageBitmap()操作。您可以使用相同的位图和任何ImageViews显示他们请你。

Hi I have a tableLayout and am populating the layout with ImageView[][] using a nested for loop. I'm currently trying to click on an ImageView and rearrange the ImageView[][] data then refresh the screen to reflect the rearrangement. Is there a way to do this? Apparently I can't call the setContentView more than once.

Edit: you can see this is the code for the onclick event. I setContentView of the original TableLayout ('tl') in the onCreate event and can't call it again here.

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case 1: 
        image_array = switchTile(image_array, 2,1,0,0);
        Toast.makeText(this, "1 clicked!", Toast.LENGTH_LONG).show();

    }

    tl.removeAllViewsInLayout();

    for(int i = 0; i < level; i++){
        TableRow new_tr = new TableRow(this);
        new_tr.setLayoutParams(layout_image);

        for(int j = 0; j< level; j++){
            new_tr.addView(image_array[i][j]);
        }
        tl.addView(new_tr);
    }

    tl.invalidate();

}

解决方案

If all you want to do is move the images around, you can just do setImageBitmap () operations on the existing ImageViews. You can use the same bitmaps and display them on whichever ImageViews you please.

这篇关于刷新tableLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆