首页 \ 问答 \ AlertDialog上的线程(Thread on AlertDialog)

AlertDialog上的线程(Thread on AlertDialog)

我创建了从AlertDialog继承的类。 此类启动线程,通过Internet检查某些值(长操作时间)。 该对话框有单个按钮(POSITIVE_BUTTON)。 应该禁用此按钮,直到线程结束。 但我不知道如何从线程启用此按钮。

我的代码:

public MyDialog(Context context) {
    super(context);
    View view = getLayoutInflater().inflate(R.layout.dialog, null);
    setView(view);

    getButton(BUTTON_POSITIVE).setEnabled(false);

    new Thread(new Runnable() {
        public void run() {
            // Long operation time code
            getButton(BUTTON_POSITIVE).setEnabled(true); // CRASH!!!
        }
    }).start();    
}

错误说我从另一个线程更改了视图。 我不能使用runOnUIThread方法,因为它不会在AlertDialog中退出。 我该怎么办?


I created class that inheritance from AlertDialog. This class start thread that check some value over the internet (long operation time). The dialog have single button (POSITIVE_BUTTON). this button should be disable until the thread will end. But I don't know how to make this button enabled from the thread.

My code:

public MyDialog(Context context) {
    super(context);
    View view = getLayoutInflater().inflate(R.layout.dialog, null);
    setView(view);

    getButton(BUTTON_POSITIVE).setEnabled(false);

    new Thread(new Runnable() {
        public void run() {
            // Long operation time code
            getButton(BUTTON_POSITIVE).setEnabled(true); // CRASH!!!
        }
    }).start();    
}

The error says that I change view from another thread. And I can't use the runOnUIThread method because it not exits in AlertDialog. What should I do?


原文:https://stackoverflow.com/questions/17113265
更新时间:2023-10-01 06:10

最满意答案

colsep参数采用数字向量,指示列是否应该用颜色空间分隔。 从文档:

(optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color sepcolor

在您的示例中,这将是这样的:

heatmap.2(as.matrix(order_by27_T[rowsToDraw,]), colsep=1:5,
     sepcolor=c("red", "blue"), ....)

这会将第1列与第5列分开,颜色为redblue


如果你只想指定一个自定义调色板(不是你要求的),这里有一些代码:

full = matrix(runif(100, -5, 5), ncol= 10)
my_p = colorRampPalette(c("white","pink","green"))
breaks = c(seq(min(full), 0, length.out=128),
           seq(0, max(full), length.out=128))
heatmap.2(full, dendrogram="row", Colv=FALSE,
          col=my_p, key=TRUE, 
          breaks=breaks, symkey=FALSE, density.info="none",
          trace="none", cexRow=0.5, cexCol=0.75)

The colsep argument takes a vector of numbers indicating whether the columns should be separated by a space of colour. From the documentation:

(optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color sepcolor

In your example, this would be something like:

heatmap.2(as.matrix(order_by27_T[rowsToDraw,]), colsep=1:5,
     sepcolor=c("red", "blue"), ....)

This would separate columns 1 to 5 with the colours red and blue


Just in case you only want to specify a custom palette (not what you asked for), here is some code:

full = matrix(runif(100, -5, 5), ncol= 10)
my_p = colorRampPalette(c("white","pink","green"))
breaks = c(seq(min(full), 0, length.out=128),
           seq(0, max(full), length.out=128))
heatmap.2(full, dendrogram="row", Colv=FALSE,
          col=my_p, key=TRUE, 
          breaks=breaks, symkey=FALSE, density.info="none",
          trace="none", cexRow=0.5, cexCol=0.75)

相关问答

更多
  • 使用capture.output尝试以下修改。 这对我来说没有打印NULL 。 ```{r, message=FALSE,warning=FALSE, echo=FALSE} require(gplots) data(mtcars) x <- as.matrix(mtcars) res <- capture.output(heatmap.2(x,srtCol=0)) ``` 有一些更好的方法可以选择heatmap.2但我没有在文档中看到它。 这是基于以下SO post 在R中抑制一个命令的输出 。 Tr ...
  • colsep参数采用数字向量,指示列是否应该用颜色空间分隔。 从文档: (optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color sepcolor 在您的示例中,这将是这样的: heatmap.2(as.matrix(order_by27_T[rowsToDraw,]), co ...
  • 如果您仔细阅读了“ ?heatplot.2的文档,您将在参数列表的底部看到以下内容: lmat,lhei,lwid视觉布局:位置矩阵,列高,列宽。 请参阅下文了解详情 细节是: 可以通过为lmat,lwid和lhei指定适当的值来覆盖此布局。 lmat控制每个元素的相对位置,而lwid控制列宽,lhei控制行高。 有关如何使用这些参数的详细信息,请参阅帮助页面以获取布局。 例如: data(mtcars) x <- as.matrix(mtcars) rc <- rainbow(nrow(x), st ...
  • 要为红色着色行名称,您需要执行以下操作: data(mtcars) x<-scale(mtcars) set.seed(123) tf<-sample(rownames(x), 5) 使用行名称的颜色创建矢量cols。 红色为tf,黑色为其他任何地方 #initiate cols with all black cols <- rep('black', nrow(mtcars)) #turn red the specified rows in tf cols[row.names(mtcars) %in% ...
  • 这里的想法是创建自己的色标(基本上你必须定义颜色的范围)。 您可以使用RColorBrewer包中的colorRampPalette : http://cran.r-project.org/web/packages/RColorBrewer/ 看看以下链接,他们找到了解决方法: 如何更改R中的heatmap.2颜色范围? The idea here is to create your own color scale (basically you have to define the ranges for t ...
  • 您没有指定Rowv=FALSE并且默认情况heatmap.2被重新排序(在heatmap.2帮助中,对于参数Rowv :“确定是否以及如何对行树状图进行重新排序。默认情况下,它是TRUE,这意味着树状图被计算并且如果为NULL或FALSE,则不计算树状图并且不进行重新排序。“) 因此,如果您想要根据最后一列对行进行排序,您可以执行以下操作: mat_data<-mat_data[order(mat_data[,ncol(mat_data)],decreasing=T),] 接着 heatmap.2(mat ...
  • 经过一些调查后,我注意到在通过热图或热图运行我的矩阵后,值发生了变化,例如从提供的数据集中获取的相互作用。 Pacdh-2和pegg-2 在将基质送至热图之前给出0.0250313的值。 之后,我使用result $ carpet查看了矩阵值,然后是值 -0.224333135 -1.09805379 对于这两种互动 那么我决定根据聚类矩阵中的树形图重新排序原始矩阵,这样我就可以确定这些值是相同的。 我使用了以下堆栈溢出问题求助: 热图中的行顺序? 这是用于此的代码: rowInd <- rev(order ...
  • 将标签插入NA的矢量并将其传递给labCol参数对我labCol 。 library(gplots) m <- matrix(rnorm(1000), ncol=100) labvec <- c(rep(NA, 100)) labvec[c(1,20,40,60,80,100)] <- c(1,20,40,60,80,100) heatmap.2(m, trace="none", Rowv = T, Colv = F, labCol = labvec, srtCol = 0) srt参数也可用于将标签水 ...
  • 可以使用布局参数来完成热图2的定位元素。 layout(mat = lmat, widths = lwid, heights = lhei) 我使用以下内容获得了一个非常可接受的热图图。 heatmap.2(x, Rowv=NA, Colv=NA, scale="none", main="This title will be cut off by the white space where the non-existant key is supposed to go ...
  • 您可以使用image绘制单列数据集的热图: library(graphics) mat <- matrix(c(-1, -1, -.9, -.8, -.2, .3, .6, .7, .8, 1)) image(mat) You can plot a heatmap of a one-column dataset with image: library(graphics) mat <- matrix(c(-1, -1, -.9, -.8, -.2, .3, .6, .7, .8, 1)) image(mat ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。