我希望能够在指定的延迟后调用以下方法.在目标c中有类似的东西:
[self performSelector:@selector(DoSomething) withObject:nil afterDelay:5];
Run Code Online (Sandbox Code Playgroud)
android中有没有与java相同的方法?例如,我需要能够在5秒后调用方法.
public void DoSomething()
{
//do something here
}
Run Code Online (Sandbox Code Playgroud) 我HorizontalScrollView在布局中使用a ,我需要确定用户已达到滚动的起点和终点.
因为ListView我已经尝试过了onScrollListener,可以找到滚动的起点和终点.
我尝试在我做同样的事情,Scrollview但似乎不可能.有没有其他可能的方法来实现我的需要.
提前致谢.
基本上我需要暂停(基于几秒钟)才能进行一个操作,以便用户可以看到在采取下一个操作之前会发生什么.因此,对于二十一点,当它是经销商的轮到他决定击中时,他会命中,一张牌被添加,然后他决定接下来该做什么.因此,在他决定下一步该做什么之前,我希望代码暂停,以便可以"看到"经销商在做什么,这样经销商不会在不到一秒的时间内完成他的行动而玩家只能看到结果.
提前致谢!
我应该注意到我尝试过使用wait(这里插入数字); 但我被eclipse告知它会导致堆栈拦截错误或类似的东西并抛出异常,从而无所作为:(
嗯,这很有趣,(我编程的方式是"有趣的"至少可以说)我做了Thread.sleep(5000)并把它扔在一个试试捕获,它确实睡了5秒然后继续做代码.但是,在我按下按钮之后才会显示我对视图的更新(真的很讨厌事件驱动编程).
我正在Android中编写一个用户修改SQL数据库的活动.UI由用户输入名称的EditText和用户输入人物吸引力的Seekbar组成.下面有一堆按钮:添加,编辑,查看,删除.
当用户单击"编辑"按钮时,将显示一个输入对话框,要求用户输入记录编号.完成后,将加载该记录.
我遇到的问题是inputdialog会显示,而当用户输入记录no时,编辑方法的其余部分将继续进行,以便当用户输入输入时 - 没有任何事情发生,因为该功能已经已经完成.
为了解决这个问题,我决定使用多线程(我没有太多使用经验).当按下编辑按钮时,主UI线程被阻止(使用wait() - 这是因为我不希望UI在用户输入记录ID时处于活动状态.)并且输入对话框显示在单独的线程.
输入输入后,将通知线程并继续编辑功能的其余部分.(代码如下).
问题是,当我在UI线程上调用wait函数时,我收到一条错误,上面写着"对象在wait()之前没有被线程锁定".如何锁定UI线程?
我知道一般不应该阻止UI线程,但我认为在这种情况下它是可以的,因为我不希望它接受任何用户输入.
谢谢你的帮助.
public class Attractivometer extends Activity implements OnClickListener {
private Button buttonAddRecord, buttonEditRecord, buttonSaveChanges;
private Button buttonDeleteRecord, buttonViewRecord;
private EditText fieldName;
private SeekBar seekbarAttractiveness;
private String inputFromInputDialog=null;
private Thread inputThread;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.Attractivometer);
buttonAddRecord = (Button) findViewById(R.id.buttonAddRecord);
buttonSaveChanges = (Button) findViewById(R.id.buttonSaveChanges);
buttonEditRecord = (Button) findViewById(R.id.buttonEditRecord);
buttonDeleteRecord = (Button) findViewById(R.id.buttonDeleteRecord);
buttonViewRecord = (Button) findViewById(R.id.buttonViewRecord);
fieldName = (EditText) findViewById(R.id.fieldName);
seekbarAttractiveness = (SeekBar) findViewById(R.id.seekbarAttractiveness);
buttonAddRecord.setOnClickListener(this);
buttonSaveChanges.setOnClickListener(this);
buttonEditRecord.setOnClickListener(this);
buttonDeleteRecord.setOnClickListener(this); …Run Code Online (Sandbox Code Playgroud) 我希望我的程序在我的同时等待10秒,但它不起作用我尝试使用Thread.sleep(10000);但它不是10秒
while (true) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 5; j++) {
if (matrixVacancy[i][j] == 1) {
completeParking(i, j, R.color.vaga_ocupada);
} else {
completeParking(i, j, R.color.cor_chao);
}
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
int a, b, c, d, e, f, g, h, i;
a = (int) (Math.random() * 2); // indice i
b = (int) (Math.random() * 5); // indice j …Run Code Online (Sandbox Code Playgroud)