package com.example.pranesh.swiperdiaper
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.support.v4.view.GestureDetectorCompat;
public class MainActivity extends ActionBarActivity implements
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{
private GestureDetector akashMessage;
private GestureDetectorCompat gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
akashMessage = (TextView)findViewById(R.id.akashMessage);
this.gestureDetector=new GestureDetectorCompat(this,this);
gestureDetector.setOnDoubleTapListener(this);
}
//gesture begins//
@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
akashMessage.setText("onSingleTapConfirmed");
return true;
}
@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
akashMessage.setText("onDoubleTap");
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent motionEvent) {
akashMessage.setText("onDoubleTapEvent");
return true;
}
@Override
public boolean onDown(MotionEvent motionEvent) {
akashMessage.setText("onDown");
return true;
}
@Override
public void onShowPress(MotionEvent motionEvent) {
}
@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
akashMessage.setText("onSingleTapUp");
return true;
}
@Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
akashMessage.setText("onScroll");
return true;
}
@Override
public void onLongPress(MotionEvent motionEvent) {
}
@Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
akashMessage.setText("onFling");
return true;
}
//gesture ends//
@Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is my simple android app program. the problem is i am gettinng an error: incompatible types: TextView cannot be converted to GestureDetector as well as error: cannot find symbol method setText(String)
please help me to find my bug Thank You.
What logcat throws
error: incompatible types: TextView cannot be converted to GestureDetector as well as error: cannot find symbol method setText(String)
NOT private GestureDetector akashMessage;
DO private TextView akashMessage;
Pass TextView Not GestureDetector . Just Replace it
You have declared akashMessage
as GestureDetector
Later on you are trying to assign a TextView
to it. That's why you are getting error as "TextView cannot be converted to GestureDetector".
change private GestureDetector akashMessage;
to private TextView akashMessage;
and check IDs in xml file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.