【发布时间】:2014-11-12 00:34:25
【问题描述】:
我有一个 textView,我希望当我将手指放在 textView 上时,它应该重复调用该方法。
我只知道这些监听器:onClick、onLongClick、onTouch ...所以我真的不知道该怎么做。
这是我的例子:
package de.tiendonam.touchz;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
public class GameActivity extends Activity {
TextView gameBackground;
int points = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//fullscreen
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game);
gameBackground = (TextView) findViewById(R.id.gameBackground);
gameBackground.setText("Points: 0");
gameBackground.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent e) {
int action = e.getAction();
if(action == MotionEvent.ACTION_DOWN)
{
points++;
}
else if(action == MotionEvent.ACTION_UP)
{
points = 0;
}
gameBackground.setText("Points: "+points);
return true;
}
});
}
}
(对不起我的英语不好,我不是以英语为母语的人)
【问题讨论】:
-
你试过
onLongClickListener吗?
标签: android