解决方法
使用以下代码:
tv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub return false; } });
和导入:
import android.view.View.OnLongClickListener;
如果你想要点击视图的某些部分你需要ClickableSpan.从this link复制代码.
SpannableString ss = new SpannableString("Android is a Software stack"); //ss.setSpan(new StyleSpan(Typeface.ITALIC),22,27,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View textView) { startActivity(new Intent(MyActivity.this,NextActivity.class)); } }; ss.setSpan(clickableSpan,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textView = (TextView) findViewById(R.id.hello); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance());