这是我的加减法程序代码,但问题是在手机上加入振动的最佳方法是什么,例如文本布局显示数字为-1。所以手机然后以某种方式振动-1 ..我知道我需要做一个if语句,但我似乎遇到了麻烦..这是程序的java代码..谢谢你的帮助!
package com.example.untitled3;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MyActivity extends Activity {
int counter;
Button add , sub;
TextView display;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Adds 1 to the counter
counter = counter + 1;
display.setText(" Your total is :" + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Subtract 1 from counter
counter = counter - 1;
display.setText(" Your total is :" + counter);
}
});
}
}