0

I'm trying to write an android game,

I want my person on the view would dance when I press.

and have a score keep gaining during the pressing.

how can i solve the score problem ?

Can timer help ?

And how's the difference between onlongclick and onclick ?

here is my code:

package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.text.Layout;

public class pi extends Activity {
     OnTouchListener listen1;  
     RelativeLayout f1;
     int count = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pi);
        listen1 = new OnTouchListener() {       
            private TextView txt;
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                txt = (TextView)findViewById(R.id.textView1);
                txt.setText("aaaaa");
                        return false;
            }


        };


        f1 = (RelativeLayout)findViewById(R.id.titlescreenframe);
        f1.setOnTouchListener(listen1);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_pi, menu);
        return true;
    }


}
sdabet
  • 18,360
  • 11
  • 89
  • 158
Edison
  • 79
  • 1
  • 13

1 Answers1

0

onTouch is click and release. onLongClick is click and hold until the onLongClick event fires.

To keep your score, override onTouch(). When a finger goes down, start an timer that starts to increase the score. When the finger goes up. Stop the task.

See here and here

Community
  • 1
  • 1
Simon
  • 14,407
  • 8
  • 46
  • 61