新人eclipse点击按钮触发事件
1个回答
2017-05-17
展开全部
现在是每次点击加1,我想每次加5上限是30,并打印出一句话。
(如果可以的话最好能再加上一个按钮可以每次减5,减到count = 3;为止。)
package com.txst.cs01;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView textview;
private Button button;
int count = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = (TextView)findViewById(R.id.textview);
//textview.setText("北京你好");
button = (Button)findViewById(R.id.button1);
ButtonListener buttonlistener = new ButtonListener();
button.setOnClickListener(buttonlistener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
count++;
textview.setText(count + "");
}
}
}
(如果可以的话最好能再加上一个按钮可以每次减5,减到count = 3;为止。)
package com.txst.cs01;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView textview;
private Button button;
int count = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = (TextView)findViewById(R.id.textview);
//textview.setText("北京你好");
button = (Button)findViewById(R.id.button1);
ButtonListener buttonlistener = new ButtonListener();
button.setOnClickListener(buttonlistener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
count++;
textview.setText(count + "");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询