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
最满意答案
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列分开,颜色为
red
和blue
如果你只想指定一个自定义调色板(不是你要求的),这里有一些代码:
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
andblue
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 ...
-
R中的Recenter heatmap.2(Recenter heatmap.2 in R)[2022-12-18]
如果您仔细阅读了“ ?heatplot.2的文档,您将在参数列表的底部看到以下内容: lmat,lhei,lwid视觉布局:位置矩阵,列高,列宽。 请参阅下文了解详情 细节是: 可以通过为lmat,lwid和lhei指定适当的值来覆盖此布局。 lmat控制每个元素的相对位置,而lwid控制列宽,lhei控制行高。 有关如何使用这些参数的详细信息,请参阅帮助页面以获取布局。 例如: data(mtcars) x <- as.matrix(mtcars) rc <- rainbow(nrow(x), st ... -
如何在R中的heatmap.2中为一组标签或分支着色(How to color a group of labels or branches in heatmap.2 in R)[2024-03-24]
要为红色着色行名称,您需要执行以下操作: 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% ... -
R heatmap.2键颜色(R heatmap.2 key colour)[2021-12-05]
这里的想法是创建自己的色标(基本上你必须定义颜色的范围)。 您可以使用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参数也可用于将标签水 ...
-
R - gplots - 当key = FALSE时删除heatmap.2中的空格(R - gplots - Removing white space in heatmap.2 when key=FALSE)[2022-06-06]
可以使用布局参数来完成热图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 ...