Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2011 06:19
Show Gist options
  • Save anonymous/807320 to your computer and use it in GitHub Desktop.
Save anonymous/807320 to your computer and use it in GitHub Desktop.
package com.make;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;
public class xxxAct extends Activity {
TextView q;
TextView w;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
q=(TextView)findViewById(R.id.q);
w=(TextView)findViewById(R.id.w);
tv=(TextView)findViewById(R.id.tv);
}
@Override
public boolean onTouchEvent (MotionEvent motionEvent)
{
int action = motionEvent.getAction ();
//int currentX = (int) motionEvent.getX ();
//int currentY = (int) motionEvent.getY ();
/*if(action==MotionEvent.ACTION_DOWN)
{
t.setText("");
}*/
if (action == MotionEvent.ACTION_MOVE)
{
int currentX = (int) motionEvent.getX ();
if(currentX>q&&currentX<q.getWidth()){//same condition for y
q.setBackgroundResource(R.drawable.white_border);
q.setTextColor(Color.WHITE);
}
}
/*
if(action==MotionEvent.ACTION_UP)
{
setContentView(R.layout.main);
t.setText("");
}*/
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="30px"
android:layout_height="30px"
android:id="@+id/q"
android:text="Q"
android:textColor="#000000"
android:layout_marginLeft="25px"
android:background="#d3d3d3"
/>
<TextView
android:layout_width="30px"
android:layout_height="30px"
android:id="@+id/w"
android:text="W"
android:textColor="#000000"
android:background="#d3d3d3"
/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment