android thread.sleep运行不通过,如果去除thread.sleep则程序运行正常。
@OverridepublicvoidonActivityCreated(BundlesavedInstanceState){super.onActivityCreate...
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final TextView textView = (TextView) getActivity().findViewById(R.id.textView1);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("线程开始".toCharArray(), 0, "线程开始".length());
new Thread(){
public void run() {
try {
int i = 0 ;
while( i < 100 ){
textView.setText(("线程开始"+i).toCharArray(), 0, ("线程开始"+i).length());
i++;
Thread.sleep(200);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
});
} 展开
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final TextView textView = (TextView) getActivity().findViewById(R.id.textView1);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("线程开始".toCharArray(), 0, "线程开始".length());
new Thread(){
public void run() {
try {
int i = 0 ;
while( i < 100 ){
textView.setText(("线程开始"+i).toCharArray(), 0, ("线程开始"+i).length());
i++;
Thread.sleep(200);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
});
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询