有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从swing到安卓进行视图更新?

安卓编程新手,但我想做的是,我有一段时间用Swing写的代码。我希望能够将其转换为在安卓系统中同样的功能。接口代码和类代码如下:

界面:

public interface CellView {
  void update();
  JComponent getComponent();
}

班级

public class ComponentCellView implements CellView {
  private JComponent component;
  public ComponentCellView(JComponent component) {
    this.component = component;
  }
  public void update() { component.repaint(); }
  public JComponent getComponent() { return component; }
}

安卓中是否有类似的功能,例如。repaint()或调用并返回特定视图的功能?我听过一些关于invalidate()方法的介绍,这可能会有所帮助,而且我相信适配器中存在一个getView方法,所以这可能是我需要为自己的自定义视图声明的内容。有什么想法吗? 谢谢


共 (1) 个答案

  1. # 1 楼答案

    我在Swing上做了很短的工作,但我不知道你想要什么样的功能。我只想确认一下你提到的几个

    • invalidate()工作,它将再次调用视图的onDraw()方法
    • 适配器确实有可以请求的getView()方法
    • 自定义视图示例如下所示:

      View myview = new View (MyActivity.this) {
      
          @Override
          protected void onDraw(Canvas canvas) {
              // TODO Auto-generated method stub
              super.onDraw(canvas);
          }
      
      };