Pass screen coordinates from button to parent - android

I am making a piano app for android. As a sample(test), I have 4 buttons in my activity. The parent is a Relative Layout and I also have a few textviews that tell the screen coordinates of the finger touch. There is one more textView("Entered Button") that detects if your finger is over a button or notThis is what it looks like:
I achieved this using the code given below.
Java
public class MainActivity extends Activity {
Button b1, b2, b3, b4;
int b1x1, b1x2, b1y1, b1y2;
private TextView xcordview;
private TextView ycordview;
private TextView buttonIndicator;
private RelativeLayout touchview;
private static int defaultStates[];
private Button mLastButton;
private final static int[] STATE_PRESSED = {
android.R.attr.state_pressed,
android.R.attr.state_focused
| android.R.attr.state_enabled };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xcordview = (TextView) findViewById(R.id.textView4);
ycordview = (TextView) findViewById(R.id.textView3);
buttonIndicator = (TextView) findViewById(R.id.button_indicator);
touchview = (RelativeLayout) findViewById(R.id.relativelayout);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
defaultStates = b1.getBackground().getState();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
touchview.setOnTouchListener(new View.OnTouchListener() {
private boolean isInside = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
xcordview.setText(String.valueOf(x));
ycordview.setText(String.valueOf(y));
for (int i = 0; i < touchview.getChildCount(); i++) {
View current = touchview.getChildAt(i);
if (current instanceof Button) {
Button b = (Button) current;
if (!isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(defaultStates);
}
if (isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(STATE_PRESSED);
if (b != mLastButton) {
mLastButton = b;
buttonIndicator.setText(mLastButton.getText());
}
}
}
}
return true;
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
}
static boolean isPointWithin(int x, int y, int x1, int x2, int y1, int y2) {
return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
}
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Y Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="X Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="B1"
android:textColor="#000000" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button1"
android:text="B2"
android:textColor="#000000" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button2"
android:text="B3"
android:textColor="#000000" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button3"
android:text="B4"
android:textColor="#000000" />
<TextView
android:id="#+id/button_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginRight="33dp"
android:text="No one"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_indicator"
android:layout_alignBottom="#+id/button_indicator"
android:layout_marginRight="29dp"
android:layout_toLeftOf="#+id/button_indicator"
android:text="Entered: "
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
So this code given above works fine as it recognizes when i swipe my finger from the white space (Relative layout) over any button. But when I swipe from a button to another button, it doesn't work. It doesn't get any coordinates, nor does it sense which button my finger is over. The below image explains best what happens when I swipe from a button to another button.
So how do I get the coordinates while swiping from one button to another?

MainActivity.java
package com.example.touch;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
MyButton b1, b2, b3, b4;
int b1x1, b1x2, b1y1, b1y2;
private TextView xcordview;
private TextView ycordview;
private TextView buttonIndicator;
private RelativeLayout touchview;
private static int defaultStates[];
private Button mLastButton;
private final static int[] STATE_PRESSED = {
android.R.attr.state_pressed,
android.R.attr.state_focused
| android.R.attr.state_enabled };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xcordview = (TextView) findViewById(R.id.textView4);
ycordview = (TextView) findViewById(R.id.textView3);
buttonIndicator = (TextView) findViewById(R.id.button_indicator);
touchview = (RelativeLayout) findViewById(R.id.relativelayout);
b1 = (MyButton) findViewById(R.id.button1);
b2 = (MyButton) findViewById(R.id.button2);
b3 = (MyButton) findViewById(R.id.button3);
b4 = (MyButton) findViewById(R.id.button4);
defaultStates = b1.getBackground().getState();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
touchview.setOnTouchListener(new View.OnTouchListener() {
private boolean isInside = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
xcordview.setText(String.valueOf(x));
ycordview.setText(String.valueOf(y));
for (int i = 0; i < touchview.getChildCount(); i++) {
View current = touchview.getChildAt(i);
if (current instanceof Button) {
Button b = (Button) current;
if (!isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(defaultStates);
b.getBackground().setAlpha(255);
}
if (isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(STATE_PRESSED);
b.getBackground().setAlpha(150);
b.performClick();
if (b != mLastButton) {
mLastButton = b;
buttonIndicator.setText(mLastButton.getText());
}
}
}
}
return true;
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
}
static boolean isPointWithin(int x, int y, int x1, int x2, int y1, int y2) {
return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
}
}
MyButton.java
package com.example.touch;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;
public class MyButton extends Button {
public MyButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyButton(Context context) {
super(context);
// // TODO Auto-generated constructor stub
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
// return super.onTouchEvent(event);
return false;
}
}
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Y Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="X Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="B1"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button1"
android:text="B2"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button2"
android:text="B3"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button3"
android:text="B4"
android:textColor="#000000" />
<TextView
android:id="#+id/button_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginRight="33dp"
android:text="No one"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_indicator"
android:layout_alignBottom="#+id/button_indicator"
android:layout_marginRight="29dp"
android:layout_toLeftOf="#+id/button_indicator"
android:text="Entered: "
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

Related

First image appearing small in size and on top left corner in a viewpager when rotate the device

Hi in my application i am using the Viewpager with PagerAdapter. it contains n number of images. but when i rotate the device when viewpager is on first image then the image shift to top left corner and appears very small. please have a look in the attached image.
code which i am using
public class CustomViewPager extends ViewPager {
private final long SWITCH_TIME_INTERVAL = 5000;
public CustomViewPager(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomViewPager(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
postDelayed(mSwither, SWITCH_TIME_INTERVAL);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height)
height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
* this Runnable is use for automatically switching the view pager item.
* #author
*/
private Runnable mSwither = new Runnable() {
#Override
public void run() {
if( CustomViewPager.this.getAdapter() != null )
{
int count = CustomViewPager.this.getCurrentItem();
if( count == (CustomViewPager.this.getAdapter().getCount() - 1) )
{
count = 0;
}else
{
count++;
}
//Log.d(this.getClass().getName(), "Curent Page " + count + "");
CustomViewPager.this.setCurrentItem(count, true);
}
CustomViewPager.this.postDelayed(this, SWITCH_TIME_INTERVAL);
}
};
#Override
public boolean onTouchEvent(MotionEvent arg0) {
switch (arg0.getAction()) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP :
postDelayed(mSwither, SWITCH_TIME_INTERVAL);
break;
default:
removeCallbacks(mSwither);
break;
}
return super.onTouchEvent(arg0);
} }
//PagerAdapter onInstantiateItem code..
#Override
public Object instantiateItem(ViewGroup container, final int position) {
mImageFetcher.setLoadingImage(R.drawable.placeholder_tabportrait);
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.test_fragment1, container, false);
description = (TextView) itemView.findViewById(R.id.description);
title = (TextView) itemView.findViewById(R.id.car_title);
published = (TextView) itemView.findViewById(R.id.date_data);
author = (TextView) itemView.findViewById(R.id.author);
jumbo_tron_image = (ImageView) itemView.findViewById(R.id.jumbo_imgae);
TrayItem trayItem = getData(position);
if (null != trayItem) {
if (trayItem.getType() != null) {
if (trayItem.getImages() != null) {
mImageFetcher.loadImage(trayItem.getImages().getWidget(),
jumbo_tron_image);
}
return itemView;
}
//xml code.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:background="#color/white">
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_horizontal|center_vertical"
android:orientation="vertical"
>
<ImageView
android:id="#+id/jumbo_imgae"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="300dp"
/>
</FrameLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/container_height"
android:layout_below="#+id/main_container">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:id="#+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:textStyle="bold"
android:layout_weight="0.5"
android:textColor="#color/black"
android:id="#+id/car_title"
android:maxLines="2"
android:ellipsize="end"
android:textSize="20sp"
android:text=" "/>
<ImageView
android:id="#+id/iv_add_test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:paddingTop="10dp"
android:src="#drawable/add_icon"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/car_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/linearLayout3"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/date_data"
android:layout_width="90dp"
android:layout_height="18dp"
android:text=""
android:textSize="13sp"
android:layout_gravity="left"
android:gravity="center"
android:textColor="#color/white"
android:background="#drawable/date_bg"/>
<TextView
android:id="#+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:textColor="#color/black"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout> </RelativeLayout>

DoubleTap gesture on a Image View

I am a beginner in Android and trying to make a simple tic-tac-toe game . At any time in the game , When a user double tap on a ImageView , I want the images to change (i.e) X will change to O and O will change to X . How do i implement that ?
Here is my code
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.view.GestureDetectorCompat;
public class MainActivity extends AppCompatActivity implements OnGestureListener ,GestureDetector.OnDoubleTapListener {
private GestureDetectorCompat gestureDetector;
int activePlayer =0; // if its 0 -> Cross , if its 1 -> circle
boolean gameActive = true;
int[] gameState ={2,2,2,2,2,2,2,2,2};
int[][] winningPosition = {{0,1,2},{3,4,5},{6,7,8},{0,4,8},{2,4,6},{0,3,6},{1,4,7},{2,5,8}};
ImageView counter;
public void dropIn (View view) {
counter = (ImageView) view;
System.out.println(counter.getTag().toString());
int tapCounter = Integer.parseInt(counter.getTag().toString());
if (gameState[tapCounter] == 2 && gameActive) {
gameState[tapCounter] = activePlayer;
counter.setTranslationY(-1000f);
if (activePlayer == 0) {
counter.setImageResource(R.drawable.o);
activePlayer = 1;
} else {
counter.setImageResource(R.drawable.a);
activePlayer = 0;
}
counter.animate().translationYBy(1000f).setDuration(600);
for(int[] winningPositions : winningPosition)
{
if(gameState[winningPositions[0]] == gameState[winningPositions[1]] && gameState[winningPositions[1]] == gameState[winningPositions[2]]
&& gameState[winningPositions[1]] != 2)
{
String winner = "Player 1";
gameActive = false;
if(gameState[winningPositions[0]] == 1)
{
winner = "Player 2";
}
TextView winnerMessage = (TextView) findViewById(R.id.winnerMessage);
winnerMessage.setText(winner + " has won !");
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.VISIBLE);}
else
{
boolean gameOver = true;
for(int counterState : gameState)
{
if(counterState == 2)
gameOver = false;
}
if(gameOver)
{
TextView winnerMessage = (TextView) findViewById(R.id.winnerMessage);
winnerMessage.setText("Its a draw");
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.VISIBLE);
}
}
}
}
}
#Override
public boolean onDoubleTap(MotionEvent e) {
if(gameState[0] ==0 || gameState[1] ==0 || gameState[2] ==0)
{
for (int i = 0;i<9;i++)
{
if(gameState[i] == 0)
{
counter.setImageResource(0);
counter.setImageResource(R.drawable.a);
gameState[i]=1;
}
else {
counter.setImageResource(R.drawable.a);
gameState[i]=0;
}
}
}
return true;
}
#Override
public boolean onDoubleTapEvent(MotionEvent e) {
Toast.makeText(getApplicationContext(),"Double Tap Event",Toast.LENGTH_LONG).show();
return true;
}
#Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
public void exit()
{
Intent intent = new Intent(this, IntroActivity.class);
startActivity(intent);
}
public void playAgain(View view)
{
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.INVISIBLE);
activePlayer =0;
gameActive=true;
for(int i=0;i<gameState.length;i++)
{
gameState[i]=2;
}
GridLayout tableGrid = (GridLayout) findViewById(R.id.tableBorder);
for(int i=0;i<tableGrid.getChildCount();i++)
{
((ImageView) tableGrid.getChildAt(i)).setImageResource(0);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.gestureDetector = new GestureDetectorCompat(this,this);
gestureDetector.setOnDoubleTapListener(this);
}
#Override
public boolean onDown(MotionEvent e) {
return false;
}
#Override
public void onShowPress(MotionEvent e) {
}
#Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
#Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
#Override
public void onLongPress(MotionEvent e) {
}
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
}
And my XML Code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.adarshjayakumar.mygame.MainActivity"
android:background="#f2eddc">
<GridLayout
android:layout_width="302dp"
android:layout_height="302dp"
android:columnCount="3"
android:rowCount="3"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_centerInParent="true"
android:layout_alignParentRight="false"
android:background="#drawable/able"
android:id="#+id/tableBorder">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_row="0"
android:layout_column="0"
android:tag="0"
android:onClick="dropIn"
/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView1"
android:layout_row="0"
android:layout_column="1"
android:tag="1"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:layout_row="0"
android:layout_column="2"
android:tag="2"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView3"
android:layout_row="1"
android:layout_column="0"
android:tag="3"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView4"
android:layout_row="1"
android:layout_column="1"
android:tag="4"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView5"
android:layout_row="1"
android:layout_column="2"
android:tag="5"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView6"
android:layout_row="2"
android:layout_column="0"
android:tag="6"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView7"
android:layout_row="2"
android:layout_column="1"
android:tag="7"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView8"
android:layout_row="2"
android:layout_column="2"
android:tag="8"
android:onClick="dropIn" />
</GridLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_alignParentBottom="false"
android:layout_centerVertical="true"
android:background="#f96262"
android:id="#+id/playAgainLayout"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Game Over"
android:id="#+id/textView"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play Again"
android:id="#+id/button"
android:layout_marginTop="60dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginStart="48dp"
android:onClick="playAgain" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/button2"
android:layout_alignTop="#+id/button"
android:layout_toEndOf="#+id/textView"
android:onClick="exit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play 1 has won"
android:id="#+id/winnerMessage"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:textSize="18dp" />
</RelativeLayout>
</RelativeLayout>
It's always good to read up on the original Google documents when u first start. http://developer.android.com/reference/android/support/v4/view/GestureDetectorCompat.html gesture detector lets u detect double click.

How to toggle touch event between nested Relative layouts?

I have a Relative layout holds a surface view and another Relative layout (Nested)..
1 ) I want to receive touch events separately for Surface view, if touch events are out of child relative layout. ??
2) if my touch events falls on child relative layout, then the current touch event should not go to surface view.
How to achieve this toggle ???
Thanks in advance..!
Below is my Activity:
public class DragAndDropBasicActivity extends Activity implements OnTouchListener {
private RelativeLayout letterView;
private RelativeLayout mainLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
mainLayout.setOnTouchListener(this);
letterView = (RelativeLayout) findViewById(R.id.mlKnobView);
letterView.setOnTouchListener(this);
}
private boolean dragging = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
boolean eventConsumed = true;
int x = (int)event.getX();
int y = (int)event.getY();
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
if (v == letterView) {
dragging = true;
eventConsumed = false;
}
} else if (action == MotionEvent.ACTION_UP) {
dragging = false;
eventConsumed = false;
} else if (action == MotionEvent.ACTION_MOVE) {
if (v != letterView) {
if (dragging) {
setAbsoluteLocationCentered(letterView, x, y);
}
}
}
return eventConsumed;
}
private void setAbsoluteLocationCentered(View v, int x, int y) {
setAbsoluteLocation(v, x - v.getWidth() / 2, y - v.getHeight() / 2);
}
private void setAbsoluteLocation(View v, int x, int y) {
RelativeLayout.LayoutParams alp = (RelativeLayout.LayoutParams) v.getLayoutParams();
alp.leftMargin = x;
alp.topMargin = y;
v.setLayoutParams(alp);
}
}
Below my Xml File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="#+id/surfaceView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/mlKnobView"
android:layout_width="260dip"
android:layout_height="260dip"
android:layout_below="#+id/txtView"
android:background="#drawable/border" >
<Button
android:id="#+id/button_down"
style="?android:attr/buttonStyle"
android:layout_width="140dip"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dip"
android:background="#drawable/button_down"
android:text="Down" />
<com.example.RotaryKnob
android:id="#+id/jogView"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_above="#id/button_down"
android:layout_below="#+id/button_up"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button_left"
style="?android:attr/buttonStyle"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_above="#id/button_down"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/jogView"
android:background="#drawable/button_left"
android:text="Left" />
<Button
android:id="#+id/button_right"
style="?android:attr/buttonStyle"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_above="#id/button_down"
android:layout_alignBaseline="#id/button_left"
android:layout_alignBottom="#id/button_left"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/jogView"
android:background="#drawable/button_right"
android:text="Right" />
<Button
android:id="#+id/button_up"
style="?android:attr/buttonStyleSmall"
android:layout_width="140dip"
android:layout_height="60dip"
android:layout_above="#+id/button_left"
android:layout_alignLeft="#+id/button_down"
android:layout_below="#+id/windowHeader"
android:background="#drawable/button_up"
android:text=" UP " />
</RelativeLayout>
<TextView
android:id="#+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Hai" />
</RelativeLayout>

how to make Footer buttons appears while dragging screen down in android like in facebook app

I wanna make footer buttons in android one way is to simply make buttons and align them to bottom but I want the footer like in Facebook android app whenever we drag screen down three buttons appears for status , photo , checkin.
How to do this ??
To get a list like the following image, create a layout.xml as follows after the sample image
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/header" >
<LinearLayout
android:id="#+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:background="#drawable/button_bg_drawable" >
<ImageView
android:id="#+id/imageView0"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|left"
android:background="#drawable/button_bg_drawable"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/back_btn_small" />
</LinearLayout>
<EditText
android:id="#+id/headerText"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toRightOf="#id/BtnSlide"
android:background="#android:drawable/editbox_background_normal"
android:editable="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="normal" />
<AutoCompleteTextView
android:id="#+id/filterNewProject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="#id/BtnSlide"
android:background="#drawable/bg_input_blue"
android:completionThreshold="1"
android:hint="Search for a locality, developer or project"
android:textColor="#color/black"
android:textSize="14sp"
android:visibility="gone" />
<Button
android:id="#+id/clearAutoCompleteList"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/custom_button_clear"
android:paddingLeft="20dp"
android:visibility="gone" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:background="#drawable/seaerch_glass" />
<View
android:id="#+id/sep_header"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="#id/tabBar"
android:background="#d5d5d5"
android:visibility="visible" />
</RelativeLayout>
<include
android:id="#+id/footerLayout"
layout="#layout/post_requirement_footer"
android:visibility="gone" />
<ListView
android:id="#+id/projectsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footerLayout"
android:layout_below="#id/headerLayout"
android:divider="#color/white"
android:dividerHeight="1.5dp" >
</ListView>
<RelativeLayout
android:id="#+id/zeroResultsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footerLayout"
android:layout_below="#id/headerLayout"
android:visibility="gone" >
<ImageView
android:id="#+id/emptyIllustration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/no_results_illustration" />
</RelativeLayout>
<com.housing.utils.QuickReturnRelativeLayoutFooter
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:background="#color/transparent" >
<RelativeLayout
android:id="#+id/bottomListViewContainer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/footer_bg" >
<ImageButton
android:id="#+id/filterButtonFooter"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/button_bg_drawable"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:src="#drawable/filter_icon" />
<ImageButton
android:id="#+id/subscribeButtonFooter"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/button_bg_drawable"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:src="#drawable/subscribe_iphone"
android:visibility="visible" />
<TextView
android:id="#+id/resultsText"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="end"
android:paddingTop="10dp"
android:scrollHorizontally="false"
android:singleLine="false"
android:text=""
android:textColor="#color/black"
android:textSize="15dp"
android:visibility="visible" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/resultsText"
android:paddingRight="5dp"
android:paddingTop="15dp"
android:src="#drawable/filter_normal"
android:visibility="gone" />
</RelativeLayout>
</com.housing.utils.QuickReturnRelativeLayoutFooter>
</RelativeLayout>
Here is the Class com.housing.utils.QuickReturnRelativeLayoutFooter
PS : Replace com.housing.utils with your package name
package com.housing.utils;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.RelativeLayout;
public class QuickReturnRelativeLayoutFooter extends RelativeLayout implements
OnScrollListener {
private class ChildDescriptor {
public int index;
public int total;
public int drawable;
public ChildDescriptor(int index) {
this.index = index;
}
public int getApproximateScrollPosition() {
return index * total + (total - drawable);
}
}
public int MAX_HEIGHT_DP =60;
public int MIN_HEIGHT_DP = 0;
public static final int SCROLL_DIRECTION_INVALID = 0;
public static final int SCROLL_DIRECTION_UP = 1;
public static final int SCROLL_DIRECTION_DOWN = 2;
private int direction = SCROLL_DIRECTION_INVALID;
private ChildDescriptor lastchild;
private OnScrollListener onscrolllistener;
private int maxheight;
private int minheight;
public QuickReturnRelativeLayoutFooter(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
calculateMinMax();
}
public QuickReturnRelativeLayoutFooter(Context context, AttributeSet attrs) {
super(context, attrs);
calculateMinMax();
}
public QuickReturnRelativeLayoutFooter(Context context) {
super(context);
calculateMinMax();
}
private void calculateMinMax() {
DisplayMetrics metrics = getResources().getDisplayMetrics();
maxheight = (int) (metrics.density * (float) MAX_HEIGHT_DP);
minheight = (int) (metrics.density * (float) MIN_HEIGHT_DP);
}
private void adjustHeight(int howmuch, int max, int min) {
if ((howmuch < 0) && (direction != SCROLL_DIRECTION_UP)) {
direction = SCROLL_DIRECTION_UP;
return;
} else if ((howmuch > 20) && (direction != SCROLL_DIRECTION_DOWN)) {
direction = SCROLL_DIRECTION_DOWN;
return;
}
int current = getHeight();
current += howmuch;
if (current < min) {
current = min;
} else if (current > max) {
current = max;
}
RelativeLayout.LayoutParams f = (RelativeLayout.LayoutParams) getLayoutParams();
if (f.height != current) {
f.height = current;
setLayoutParams(f);
}
if (direction == SCROLL_DIRECTION_UP
&& Math.abs(f.topMargin) <= current) {
// if (f.topMargin != howmuch) {
//
// f.topMargin = howmuch + f.topMargin;
//
// if (f.topMargin > 0) {
// f.topMargin = -f.topMargin - 10;
// }
//
// }
// mBottomListViewContainer.setVisibility(View.GONE);
f.bottomMargin = -100;
setLayoutParams(f);
} else if (direction == SCROLL_DIRECTION_DOWN) {
if (f.bottomMargin != 0) {
f.bottomMargin = 0;
setLayoutParams(f);
}
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
ChildDescriptor currentchild = getFirstChildItemDescriptor(view,
firstVisibleItem);
try {
adjustHeight(lastchild.getApproximateScrollPosition()
- currentchild.getApproximateScrollPosition(), maxheight,
minheight);
lastchild = currentchild;
} catch (NullPointerException e) {
lastchild = currentchild;
} catch (Exception e) {
}
if (onscrolllistener != null) {
onscrolllistener.onScroll(view, firstVisibleItem, visibleItemCount,
totalItemCount);
}
}
private ChildDescriptor getFirstChildItemDescriptor(AbsListView view,
int index) {
ChildDescriptor h = new ChildDescriptor(index);
try {
Rect r = new Rect();
View child = view.getChildAt(0);
child.getDrawingRect(r);
h.total = r.height();
view.getChildVisibleRect(child, r, null);
h.drawable = r.height();
return h;
} catch (Exception e) {
}
return null;
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (onscrolllistener != null) {
onscrolllistener.onScrollStateChanged(view, scrollState);
}
}
public void attach(AbsListView view) {
view.setOnScrollListener(this);
}
public void setOnScrollListener(OnScrollListener l) {
onscrolllistener = l;
}
}
I Have made it as a widget and Now finally to add this to your List View use
frame = (QuickReturnRelativeLayoutFooter) newProjectsView
.findViewById(R.id.frame);
frame.attach(projectsList);
where projectList is your List View
example
ListView projectList =(ListView)findViewById(R.id.projectList);
and Voila Cheers Completed Smooth as Heaven .......

Android custom TextView not intercepting OnClickListener of parent

I've made a custom TextView that draws lines for every line of text.
This custom TextView is placed in a LinearLayout along with other standard TextViews and ImageViews.
Whenever I click the normal TextViews, ImageViews or outside the custom TextView, the click is intercepted.
But, if I click on the custom TextView, the click is not intercepted.
Please help!!!
Images:
Normal state(minimized)
Maximized state
Click not detected here
Code:
NoteTextView.java
package harsha.notes.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class NoteTextView extends TextView {
boolean isMaximized = false;
public NoteTextView(Context canvas, AttributeSet attributeSet) {
super(canvas, attributeSet);
}
#Override
protected void onDraw(Canvas canvas) {
int width = getWidth();//var2.getDefaultDisplay().getWidth();
int height = getHeight();//var2.getDefaultDisplay().getHeight();
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingBottom = getPaddingBottom();
int scrollY = getScrollY();
int scrollX = getScrollX();
int lineHeight = getLineHeight();
int grossWidth = width + scrollX;
int grossHeight = height + scrollY;
int netViewHeight = lineHeight + (grossHeight - paddingTop - paddingBottom);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
//paint.setColor(1722066084);
paint.setColor(1711276032);
float fontAdjustment = 15.826172F - (paint.getFontMetrics().bottom - paint.getFontMetrics().top);
float baseline = (float)(scrollY + lineHeight - scrollY % lineHeight) - fontAdjustment;
float linePadding;
if(width != 800 && height != 480) {
linePadding = 2;
} else {
linePadding = 4;
}
while(baseline < (float)netViewHeight) {
canvas.drawLine((float)paddingLeft, baseline + (float)paddingTop + linePadding, (float)grossWidth, baseline + (float)paddingTop + linePadding, paint);
baseline += (float)lineHeight;
}
super.onDraw(canvas);
}
public boolean isMaximized(){
return isMaximized;
}
public void setMaximized(boolean maximized){
isMaximized = maximized;
if(!isMaximized){
setLines(1);
}else{
setSingleLine(false);
}
}
}
NoteListAdapter.java
package harsha.notes.Items;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import harsha.notes.DB.NotesProvider;
import harsha.notes.NoteEditActivity;
import harsha.notes.R;
import harsha.notes.view.NoteTextView;
import harsha.notes.view.ViewUtils;
import java.util.ArrayList;
public class NoteListAdapter extends ArrayAdapter<Note> {
ArrayList<Note> mNotes;
final Context mContext;
public NoteListAdapter(Context context, ArrayList<Note> notes) {
super(context, R.layout.note_item, notes);
mContext = context;
mNotes = new ArrayList<Note>();
mNotes = notes;
}
public class NoteViewHolder {
public LinearLayout preview_layout;
public TextView position;
public TextView date;
public TextView time;
//public CheckBox check;
public ImageView edit;
public ImageView delete;
public NoteTextView content;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
NoteViewHolder noteViewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.note_item, null);
noteViewHolder = new NoteViewHolder();
noteViewHolder.preview_layout = (LinearLayout) convertView.findViewById(R.id.preview);
noteViewHolder.position = (TextView) convertView.findViewById(R.id.position);
noteViewHolder.date = (TextView) convertView.findViewById(R.id.date);
noteViewHolder.time = (TextView) convertView.findViewById(R.id.time);
noteViewHolder.edit = (ImageView) convertView.findViewById(R.id.menu_edit);
noteViewHolder.delete = (ImageView) convertView.findViewById(R.id.menu_delete);
//noteViewHolder.check = (CheckBox) convertView.findViewById(R.id.check);
noteViewHolder.content = (NoteTextView) convertView.findViewById(R.id.preview_text);
}else{
noteViewHolder = (NoteViewHolder) convertView.getTag();
}
Note note = mNotes.get(position);
noteViewHolder.content.setMaximized(note.getChecked());
noteViewHolder.content.setNextFocusUpId(R.id.preview);
noteViewHolder.preview_layout.setBackgroundResource(ViewUtils.getBackground(note.getColor(), noteViewHolder.content.isMaximized()));
noteViewHolder.content.setText(note.getText());
//noteViewHolder.check.setVisibility(View.GONE);
noteViewHolder.date.setText(note.getDate());
noteViewHolder.time.setText(note.getTime());
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view){
LinearLayout preview_layout = (LinearLayout) view.findViewById(R.id.preview);
NoteTextView content = (NoteTextView) view.findViewById(R.id.preview_text);
Note note = (Note) preview_layout.getTag();
content.setMaximized(!note.getChecked());
preview_layout.setBackgroundResource(ViewUtils.getBackground(note.getColor(), !note.getChecked()));
note.setChecked(!note.getChecked());
}
});
noteViewHolder.edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LinearLayout preview_layout = (LinearLayout) view.getRootView().findViewById(R.id.preview);
Note note = (Note) preview_layout.getTag();
Intent intent = new Intent(mContext, NoteEditActivity.class);
intent.setData(Uri.withAppendedPath(NotesProvider.CONTENT_URI, Uri.encode(String.valueOf(note.getNoteID()))));
mContext.startActivity(intent);
}
});
noteViewHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LinearLayout preview_layout = (LinearLayout) view.findViewById(R.id.preview);
Note note = (Note) preview_layout.getTag();
}
});
noteViewHolder.position.setText(String.valueOf(position+1));
noteViewHolder.preview_layout.setTag(note);
convertView.setTag(noteViewHolder);
return convertView;
}
}
note_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#id/preview_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="#ff4A4A4A" android:padding="5dip" android:measureWithLargestChild="false"
android:clickable="true" android:focusable="true">
<LinearLayout android:id="#id/preview" android:focusable="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="#drawable/note_yellow_min"
android:focusableInTouchMode="true">
<LinearLayout android:layout_width="fill_parent" android:layout_height="40dip" android:layout_marginRight="0dp" android:layout_marginBottom="1dip" android:gravity="center_vertical" android:focusable="false"
android:layout_marginTop="1dip">
<ImageView android:id="#id/menu_edit" android:layout_width="37dip" android:layout_height="37dip" android:src="#drawable/menu_edit" android:contentDescription="#string/color_yellow"
android:clickable="true" android:layout_marginLeft="2dip"/>
<TextView android:id="#id/position" android:textSize="15.0dip" android:typeface="sans" android:textStyle="bold" android:textColor="#ff000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MMM" android:layout_gravity="center" android:layout_marginLeft="5dip" android:gravity="right"
android:focusable="false"/>
<TextView android:id="#id/date" android:textSize="17.0dip" android:typeface="sans" android:textStyle="bold" android:textColor="#ff000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="16 AUG 2001" android:layout_weight="1" android:layout_gravity="center" android:layout_marginLeft="8dip"
android:textIsSelectable="false" android:focusable="false"/>
<TextView android:id="#id/time" android:textSize="17.0dip" android:typeface="sans" android:textStyle="bold" android:textColor="#ff000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="20:11" android:layout_gravity="center" android:layout_marginLeft="8dip" android:layout_marginRight="8dip"
android:textIsSelectable="false" android:focusable="false"/>
<ImageView android:id="#id/menu_delete" android:layout_width="37dip" android:layout_height="37dip" android:src="#drawable/menu_delete" android:contentDescription="#string/color_yellow"
android:clickable="true" android:layout_marginLeft="2dip" android:layout_marginRight="3dip"
android:visibility="visible"/>
<ImageView android:id="#id/check" android:layout_width="37dip" android:layout_height="37dip" android:src="#drawable/menu_check" android:contentDescription="#string/color_yellow"
android:clickable="true" android:layout_marginLeft="0dp" android:layout_marginRight="3dip"
android:visibility="gone"/>
</LinearLayout>
<View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#77000000" android:focusable="false"/>
<harsha.notes.view.NoteTextView android:scrollbarStyle="outsideOverlay" android:autoLink="all" android:capitalize="sentences" android:lineSpacingExtra="4.0dip" android:text="123" android:textColor="#ff000000" android:minLines="1" android:id="#id/preview_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22dp" android:layout_marginLeft="20dp" android:layout_marginRight="25dip" android:layout_marginTop="3dip" android:layout_marginBottom="28dip" android:clickable="true"
android:typeface="sans" android:visibility="visible" android:focusable="false"
android:background="#android:color/transparent" android:linksClickable="true"
android:focusableInTouchMode="false" android:longClickable="true"
android:enabled="true"/>
</LinearLayout>
</LinearLayout>
try setting onFocusChanged listener to edittext.
Did you mean that, when you click on custom TextView, your convertView's OnClickListener didn't called onClick()?
If yes, you could try disable the custom TextView.
<harsha.notes.view.NoteTextView android:scrollbarStyle="outsideOverlay" android:autoLink="all" android:capitalize="sentences" android:lineSpacingExtra="4.0dip" android:text="123" android:textColor="#ff000000" android:minLines="1" android:id="#id/preview_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22dp" android:layout_marginLeft="20dp" android:layout_marginRight="25dip" android:layout_marginTop="3dip" android:layout_marginBottom="28dip" android:clickable="true"
android:typeface="sans" android:visibility="visible" android:focusable="false"
android:background="#android:color/transparent" android:linksClickable="true"
android:focusableInTouchMode="false" android:longClickable="true"
android:enabled="false"/>

Categories

Resources