I am creating an application that is able to detect how many times the user 
touch the screen and yet also increase a counter when the user clicks on 
the image. I tried using the ontouchlistener but it seems like it only 
calls the method to detach the number of times the screen is touched. How 
to separate this 2 functions?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);
    LinearLayout containter = (LinearLayout) findViewById(R.id.container);
    String timeData = getIntent().getExtras().getString("timeDuration");
    if(timeData == "30sec"){
        timeLeft = 30000;
    }
    else if (timeData == "40sec")
    {
        timeLeft = 40000;
    }
    else if (timeData == "50sec")
    {
        timeLeft = 50000;
    }

    textViewTime = (TextView)findViewById(R.id.textViewTime);
    textViewScore = (TextView)findViewById(R.id.textViewScore);
    textViewTime.setText(timeData);
    tempScore = String.valueOf(score);
    textViewScore.setText(tempScore);
    final CounterClass timer = new CounterClass (30000, 1000);
    containter.setOnTouchListener(this);
    drawCircle();
    timer.start();
}
public void drawCircle() {

    final LinearLayout button_container = (LinearLayout) 
findViewById(R.id.my_window);
    final ImageButton imgView = (ImageButton)findViewById(R.id.gameass);
    imgView.setImageResource(R.drawable.gameass);
    imgView.setVisibility(View.VISIBLE);
    int x = (int) (Math.random() * (button_container.getWidth() - 
imgView.getWidth()));
    int y = (int) (Math.random() * (button_container.getHeight() - 
imgView.getHeight()));
    button_container.setPadding(x, y, 0, 0);
    imgView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            imgView.setImageDrawable(null);
            score++;
            textViewScore.setText(tempScore);
            drawCircle();
        }
    });
}
@Overridepublic boolean onTouch(View v, MotionEvent event) {
    counterTouch++;
    return false;}


this is my xml file for the layout:

<?xml version="1.0" encoding="utf-8"?><LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/container">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textViewTime"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="25sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textViewScore"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/my_window">

        <ImageButton
            android:id="@+id/gameass"
            android:background="@null"
            android:maxHeight="30dp"
            android:maxWidth="30dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            />
    </LinearLayout></LinearLayout>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/08332ed3-7678-4849-8c1f-a989ce03f115%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to