我想在我的布局中添加一个TextView,它包含一个整数值,并在一段时间内继续更改它的值。例如,TextView可以将其值更改为10秒然后停止。我怎么能这样做?
答案 0 :(得分:1)
您可能需要查看CountdownTimer。代码看起来像这样:
<?php
header("Content-Type: text/plain");
mysql_connect('localhost','root','') or die('Cannot connect mysql server');
mysql_select_db('DBChemAlive') or die('cannot connect database');
$Inputdata=(isset($_GET["data"])) ? $_GET["data"] : NULL;
$data=mysql_real_escape_string(filter_var($Inputdata, FILTER_SANITIZE_SPECIAL_CHARS));
$q=mysql_query("select CompType, Method, Base from GeoAndEnergies where SMILES='".$data."' ") or die(mysql_error());
$n=mysql_num_rows($q); //not mysql_fetch_row, as that does not return count but an array
if($n>0)
{
// $info=mysql_fetch_row($q);
$val='';
while($info=mysql_fetch_row($q))
{
if($val!='')
$val.=' < ';
$val.= $info[0];
}
echo $val;
}
?>
这将创建一个运行10秒的计时器,并每秒更新一次TextView。需要注意的重要一点是参数是以毫秒为单位,而不是秒。第一个参数(在我的示例中为10,000)表示计时器的持续时间。第二个参数(1,000)确定每次调用CountDownTimer myCountDown = new CountDownTimer(10000, 1000){
public void onTick(long millisUntilFinished) {
myTextView.SetText(String.valueOf(millisUntilFinished / 10));
}
public void onFinish() {
myTextView.SetText("Done!");
}
}.start();
之间发生的毫秒数。