asked    Lewis     2018-10-22       android       70 view        1 Answer

[SOLVED] Gridview Scroll with OnTouchListener

Basically, I want to fast select item as well as scroll Gridview. In OnItemClickListener scroll working fine but its not fast select multiple item like OnTouchListener.

My code:

gridView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent me) {

            int action = me.getActionMasked();  
            float currentXPosition = me.getX();
            float currentYPosition = me.getY();
            int position = gridView.pointToPosition((int) currentXPosition, (int) currentYPosition);

            switch (action) {
                case (MotionEvent.ACTION_MOVE):

                break;
                case (MotionEvent.ACTION_UP):
                    if (position != -1) {
                        //Here my logic to add item in basket list 
                        return true;
                    }
            }         
            return false;
        }
    });

Right now its scroll and add item as well. How I stop ACTION_UP(selection Item) event after ACTION_MOVE(when scroll)?

  1 Answer  

        answered    Nora     2018-10-22      

I was applying this code for scroll gridview on OntouchListener and prevent scroll on select item. And work fine in my side. If anyone have better solution bring it on.

My Code:

private int moveCount=0;
private boolean ignore = false;

gridView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent me) {

            v.getParent().requestDisallowInterceptTouchEvent(true);
            int action = me.getActionMasked();  // MotionEvent types such as ACTION_UP, ACTION_DOWN
            float currentXPosition = me.getX();
            float currentYPosition = me.getY();
            int position = gridView.pointToPosition((int) currentXPosition, (int) currentYPosition);
            if (ignore && action == MotionEvent.ACTION_UP)
                return false;
            switch (action) {
                case (MotionEvent.ACTION_MOVE):
                    moveCount++;
                    Log.d(DEBUG_TAG, "Action was MOVE " + position);
                    if(moveCount>3) {
                        ignore = true;
                    }

                    break;
                case (MotionEvent.ACTION_UP):
                    addItem(position);
                    Log.d(DEBUG_TAG, "Action was UP " + position);
                    return true;

                case (MotionEvent.ACTION_DOWN):
                    Log.d(DEBUG_TAG, "Action was DOWN " + position);
                    moveCount=0;
                    ignore = false;
                    return true;
                case (MotionEvent.ACTION_CANCEL):
                    addItem(position);
                    moveCount=0;
                    ignore = false;
                    gridView.setFocusable(true);

                    Log.d(DEBUG_TAG, "Action was CANCEL " + position);
                    return true;
                case (MotionEvent.ACTION_OUTSIDE):
                    Log.d(DEBUG_TAG, "Movement occurred outside bounds " +
                            "of current screen element " + position);
                    return true;

            }
            Log.d("clickTouch=", "" + position);
            return false;
        }
    });




Your Answer





 2018-10-22         Lindsay

Laravel Belongsto many relationship with additional column

I have been facing a problem in my project. I have a belongsto many relation with additional field.For example I have two table User and Social table and a pivot table named social_user. Here my user model ispublic function socialinfos() { return $this->belongsToMany(Social::class)->withPivot('id')->whereNull('deleted_at');}And my social_user table is Schema::create('social_user', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('user_id'); $table->string('social_id')->nullable(); $table->string('url')->...
 php                     1 answers                     50 view
 2018-10-22         Antony

laravel replicate() method and computed database column

I'm trying to copy a row using by replicate() method:$doc = Doc::find(64618);$newdoc = $doc->replicate();$newdoc->Price= 9999; $newdoc->save();but this table contains several computed columns and I get an error that the data fields can not be updated.How can I exclude these fields when using replicate()? You can pass the columns that you want to excludes$doc = Doc::find(64618);$newdoc = $doc->replicate(['column1', 'column2']);$newdoc->Price= 9999; $newdoc->save();Here is the source you will find out if u deep dive into the core./** * Clone the model...
 laravel                     1 answers                     51 view
 2018-10-22         Alfred

Laravel / MySQL when using AVG (only count first row return on a given id) - how?

My AVG(rank) will return 2 and 34 clicksSum in this case. But how can I get it to only count the first row of ranks? So that it will only take one rank of each keyword_id from each date in the interval.$interval = \DB::table('keywords')->selectRaw('keyword, url, AVG(rank) rankAvg, SUM(clicks) clicksSum ')->join('ranks', 'keywords.id', '=', 'ranks.keyword_id')->whereBetween('ranks.date', array('2018-07-20','2018-07-29'))->orderBy('clicksSum', 'DESC')->groupBy('keywords.id')->paginate(50);Table: Keywordsid keyword1 testTable: Ranksid keyword_id rank url ...
 mysql                     1 answers                     50 view