android程序开发,自定义变量a,a=1时textview显示1,a=0时 点击刷新button textview显示0,怎样实现?
展开全部
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class BaiduActivity extends Activity {
/** Called when the activity is first created. */
private TextView textView;
private Button b;
private int i ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.t);
b = (Button) findViewById(R.id.b);
i = 0 ;
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText(i+"");
i=1;
}
});
}
}
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class BaiduActivity extends Activity {
/** Called when the activity is first created. */
private TextView textView;
private Button b;
private int i ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.t);
b = (Button) findViewById(R.id.b);
i = 0 ;
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText(i+"");
i=1;
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |