coding help basic..pls help asap

0 srinivas r · September 10, 2015
package com.romala.test1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.support.v4.view.GestureDetectorCompat;

public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{

Button romalasButton = (Button)findViewById(R.id.romalasButton);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


romalasButton.setOnClickListener(
new Button.OnClickListener() {
public void OnClick(View v) {
TextView romalasText = (TextView) findViewById(R.id.romalasText);
romalasText.setText("Good Work");

}
}
);

romalasButton.setOnLongClickListener(
new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
TextView romalasText = (TextView) findViewById(R.id.romalasText);
romalasText.setText("Wrong Step");
return true;
}
}
);

romalasmessage = (TextView) findViewById(R.id.romalasmessage);
this.gestureDetector = new GestureDetectorCompat(this, this);
gestureDetector.setOnDoubleTapListener(this);
}

private TextView romalasmessage;
private GestureDetectorCompat gestureDetector;



@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
super.addContentView(view, params);
}

@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
romalasmessage.setText("onDoubleTap");
return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent motionEvent) {
romalasmessage.setText("onDoubleTapEvent");
return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
romalasmessage.setText("onSingleTapConfirmed");
return true;
}

@Override
public boolean onDown(MotionEvent motionEvent) {
romalasmessage.setText("onDown");
return true;
}

@Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
romalasmessage.setText("onFling");
return true;
}

@Override
public void onLongPress(MotionEvent motionEvent) {
romalasmessage.setText("onLongPress");

}

@Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
romalasmessage.setText("onScroll");
return true;
}

@Override
public void onShowPress(MotionEvent motionEvent) {
romalasmessage.setText("onShowPress");

}

@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
romalasmessage.setText("onSingleTapUp");
return true;
}

//////End Gestures


@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);
}
}









note--i also want to add color to background and button also

Post a Reply

Replies

Oldest  Newest  Rating
0 Dol Lod · September 11, 2015
So what exactly do you need help with?

If it's gestures you need help with, I am not familiar with those and can't help.

Adding color to the background and button I can do.
  • 1

Java / Android Development

107,266 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator