我已经在SO上阅读了关于这个主题的几个问题,但还没有找到一个可靠的答案.
我有一个framelayout,我堆叠多个自定义视图,但onTouch事件只适用于顶视图.(自定义视图与具有相同onTouch事件的所有视图相同,只是其中的多个)
的FrameLayout
我正在Android 2.2上测试它,我想知道下面的其他视图是否有任何方法可以知道触摸发生在哪里?
编辑(添加一些代码)
我正在添加一些代码,以帮助解释我遇到问题的地方.起初我只是自动onTouchEvent返回true.这使得最后一个视图(在我的情况下是customerView [2])将是唯一一个生成值的视图.
但是,一旦我添加了设置onTouchEvent为返回true或false的方法,现在返回生成值的唯一视图是customView [0].
我希望这能解决我所要求的问题.我对此很陌生,我很感谢你花时间解释它(当然我感谢你的耐心等待).
此外,我意识到我的TextView不会更新每个touchEvent的值,我正在努力修复它.
我的活动:
public class MyActivity extend Activity {
CustomView[] customView;
TextView[] textView;
int numViews 3;
//FrameLayout and Params created
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(int i = 0; i < numViews; i++) {
customView[i] = new CustomView(this, i);
//Allows the onTouch to be handled by all Views - View[0] is the …Run Code Online (Sandbox Code Playgroud) 我只是有一个关于编写一个函数的问题,该函数将在目录中搜索目录中的最新日志.我目前想出了一个,但我想知道是否有更好的(也许更合适的)这样做的方式.
我目前正在使用hdsentinel在计算机上创建日志并将日志放在目录中.日志保存如下:
/directory/hdsentinel-computername-date
ie. C:/hdsentinel-owner-2010-11-11.txt
Run Code Online (Sandbox Code Playgroud)
所以我编写了一个快速脚本,循环访问某些变量以检查最近的(在过去一周内),但在查看之后,我会质疑以这种方式做事的效率和适当程度.
这是脚本:
String directoryPath = "D:"
def computerName = InetAddress.getLocalHost().hostName
def dateToday = new Date()
def dateToString = String.format('%tm-%<td-%<tY', dateToday)
def fileExtension = ".txt"
def theFile
for(int i = 0; i < 7; i++) {
dateToString = String.format('%tY-%<tm-%<td', dateToday.minus(i))
fileName = "$directoryPath\\hdsentinel-$computerName-$dateToString$fileExtension"
theFile = new File(fileName)
if(theFile.exists()) {
println fileName
break;
} else {
println "Couldn't find the file: " + fileName
}
}
theFile.eachLine { print it }
Run Code Online (Sandbox Code Playgroud)
脚本运行正常,也许它有一些缺陷.在我继续之前,我觉得我应该继续问一下这类事情的典型路线.
所有输入都表示赞赏.
我想知道如果不能使用div操作数,如何找到整数的余数.例如:
mov eax, 400 ; 400 / 4
shr eax, 2 ; Remainder : 0
mov eax, 397 ; 397 / 4
shr eax, 2 ; Remainder : 1
mov eax, 394 ; 394 / 4
shr eax, 2 ; Remainder : 2
Run Code Online (Sandbox Code Playgroud)
移动截断剩余部分.
因此,如果不使用div(存储其余部分edx),可以做些什么来弄清楚其余部分是什么?
我在groovy中有一张看起来像下面的地图...
def book = [Title of Book: "Groovy Recipes", Author: "Scott Davis", Number of Pages: "241"]
Run Code Online (Sandbox Code Playgroud)
我将每本“书”添加到BookList中,希望以后可以获取每个值,但是当我尝试类似的方法时...
BookList.Title of Book[0] //prints something like Title[0] instead of Groovy Recipes
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有没有办法在不更改键名的情况下获取这些键/值?
我目前正在使用HtmlUnit尝试从页面中抓取一个href并且遇到了一些麻烦.
XPath是:
/html/body/div[2]/div/div/table/tbody/tr/td[2]/div/div[5]/div/div[2]/span/a
Run Code Online (Sandbox Code Playgroud)
在网页上看起来像:
<a class="t" title="This Brush" href=http://domain.com/this/that">Brush Set</a>
Run Code Online (Sandbox Code Playgroud)
在我的代码中我正在做:
hrefs = page.getByXPath("//html/body/div[2]/div/div/table/tbody/tr/td[2]/div/div[5]/div/div[2]/span/a[@class='t']")
Run Code Online (Sandbox Code Playgroud)
但是,这会返回那里的所有内容,而不仅仅是我想要的网址.
有人可以解释我必须添加什么来获得href?(也不以.html结尾)
我有一个项目,我想重命名(我正在使用Netbeans),我找不到这样做的选项.使用Java项目,它就像右键单击项目 - >重命名一样简单.
有没有办法重命名Grails项目?(不会导致其中的课程出现问题)
我希望以HH:mm:ss不使用任何外部库的格式显示我的JLabel显示值.(标签将每秒更新)
例如,以下输入以秒为单位,所需的输出如下:
Seconds: Output:
--------------------------------------------------
long seconds = 0 00:00:00
long seconds = 5 00:00:05
long seconds = 500 00:08:20
long seconds = 5000 01:23:20
Note: the seconds value is of type long
Run Code Online (Sandbox Code Playgroud)
我知道通常只会进行以下转换以获得所需的数字:
long s = 5000; //total seconds
long hrs = (s / 3600) //hours
long mins = ((s%3600)/60) //minutes
long secs = (s%60) //seconds
Run Code Online (Sandbox Code Playgroud)
但是,这会在值上留下小数.也许有某种格式可以让我抛出不需要的小数.
我所遇到的选择是String.format(),SimpleDateFormat()或者连接字符串自己.
问题是,我将每秒更新一次这个JLabel,有时甚至可以计算相当于5-6天.
所以我正在寻找一个比我更有经验的人,并且知道解决这个问题的最有效方法.
我被分配到编写一个使用堆栈计算后缀表达式的程序。
我编写了该程序,它似乎在大部分情况下都能正常工作,但是在确定表达式是否有效时遇到了问题。
以下是我所做的基本步骤:
因此,如果堆栈已经是空的,那么上面的方法效果很好,但是如果堆栈上有更多的操作数,结果就会简单地打印出来。这显然是不正确的,因为如果堆栈上还有多个操作数,它应该是一个无效的表达式。
我在想我应该做一个while(!stack.empty()) result = stack.top, stack.pop()但是,这仍然会有同样的问题。
有人可以告诉我应该如何正确测试它吗?
代码:
int main()
{
string expression;
char response;
int result = -1; //result of expression. Initialized to -1
Stack stack;
printMenu();
do {
cout << "Would you like to enter an expression? (y / n)" << endl;
cin >> response;
response = toupper(response);
switch(response)
{
case 'Y':
//needed due to …Run Code Online (Sandbox Code Playgroud) 我正在阅读C++,并想知道是否有人可以向我解释一些类操作符的一些差异.有问题的经营者是:
* & . ->
我了解其中一些,但是,我没有看到一些之间的区别.例如:
*x
&x
x.y
(*x).y
x -> y
Run Code Online (Sandbox Code Playgroud)
有人可以使用一个例子并解释一下它们会有什么不同吗?
我不经常涉及C++,但我正在学习数据结构,本书使用c ++作为语言.我现在正在设置课程.
我的问题是:
Visual Studio 2012正在咆哮着未知的变量.我在我的标题中声明了变量,所以我不太清楚为什么我遇到了这个问题.
我正在尝试重载加法和乘法运算符(作为非成员函数),但它仍然试图使用它,好像我只允许有一个参数用于重载.
这是我正在做的一些代码:
1.未识别的变量
/* Quadratic.h */
#include <iostream>
using namespace std;
class Quadratic
{
public:
// constructors
Quadratic::Quadratic()
// accessors
Quadratic::getA();
Quadratic::getB();
Quadratic::getC();
// mutators
Quadratic::setCoefficients(float coA, float coB, float coC);
private:
float a, b, c, x;
};
Run Code Online (Sandbox Code Playgroud)
Quadratic.cpp:
/* Quadratic.cpp */
#include <iostream>
#include "Quadratic.h"
using namespace std;
class Quadratic
{
// Default constructor
Quadratic::Quadratic()
{
a = 0; // Visual Studio is complaining about a, b, & c
b = 0;
c …Run Code Online (Sandbox Code Playgroud)