在一个activity里面有一个button,一个textview,button的onclick操作是一个挺耗时的操作,我想在点击button的时候让textview显示正在查询这样的字符,提示用户现在的操作,代码如下
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.network);
Button locbtn =(Button)findViewById(R.id.locbutton);
locbtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.locbutton:
TextView textview;
textview=(TextView)findViewById(R.id.querystate);
textview.setText("Accuracy: Querying..."); LocationInfo locationinfo=new LocationInfo();
locationinfo=GetLocation(cellinfos);
}
}
点击完button后,textview并不更新,而是要等到onclick事件执行完毕后,才更新textview,跟的初衷不一致,请教该如何解决
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.network);
Button locbtn =(Button)findViewById(R.id.locbutton);
locbtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.locbutton:
TextView textview;
textview=(TextView)findViewById(R.id.querystate);
textview.setText("Accuracy: Querying..."); LocationInfo locationinfo=new LocationInfo();
locationinfo=GetLocation(cellinfos);
}
}
点击完button后,textview并不更新,而是要等到onclick事件执行完毕后,才更新textview,跟的初衷不一致,请教该如何解决
而且还会出现所谓的NAR错误。必须开线程来做耗时工作。
{
// TextView更新
}
else if(event.getAction() == MotionEvent.ACTION_UP)
{
//执行
}
参考这里