Java Question How to implement OnTouchListener in a costum view?

PABLO2013

Well-Known Member
Licensed User
Longtime User
B4X:
package com.floor;
import android.content.Context;
import android.view.View;
import android.view.View.OnTouchListener;
import anywheresoftware.b4a.objects.collections.Map;

@BA.Version(1.0F)
@BA.ShortName("Croquis")
@BA.Events(values={"OnTouchListener (Value As Boolean)"})


public class croquis extends ViewWrapper<DrawGrid> implements DesignerCustomView ,OnTouchListener    {
       DrawGrid cv;
       private String eventName;
       private BA ba;

     public void Initialize(BA paramBA, String paramString)
      {
        _initialize(paramBA, null, paramString);
      }
    
      @BA.Hide
      public void _initialize(BA paramBA, Object paramObject, String paramString)
      {
        this.eventName = paramString.toLowerCase(BA.cul);
        this.ba = paramBA;
        this.cv = new DrawGrid(paramBA.context);
        cv.setOnTouchListener(this); //????
       
      }   
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
        //my code
            return true;
        }
         
   
    
public void DesignerCreateView(PanelWrapper paramPanelWrapper, LabelWrapper paramLabelWrapper, final Map paramMap)
      {
        
           this.cv = new DrawGrid(ba.context);
        
         
           paramPanelWrapper.AddView(this.cv, 0, 0,  paramPanelWrapper.getWidth(),       paramPanelWrapper.getHeight());
           paramPanelWrapper.setColor(Colors.Transparent);
      
           }

   
        //rest of code
  

}
Greetings,i wanted to know how I implement OnTouchListener in a costum view.
This is not the complete code because it is long I want some help to start this view That implements OnTouchListener , thanks
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings, thanks for the word of encouragement, the problem is that there is a method that was created to draw a simple line on a view that is a grid, I have tried this method directly adding real data and it works; but the idea is Data X and Y are aggregated by means of arg1.getX () arg1.getY () -de- ((public boolean onTouch (View arg0, MotionEvent arg1))). The problem is that the code that you kindly says correct in the onToch part does not work, thanks.

I added an image to try to clarify, I know this is very clear for you, but I do it to explain me more, tks
 

Attachments

  • croquis.png
    23.5 KB · Views: 392

PABLO2013

Well-Known Member
Licensed User
Longtime User
Thanks, I appreciate your recommendations, but I do not understand why i can not implement OnTouchListener in a costum view, it's just what you would miss, what I would not do is to miss what I have, how could I implement this would only be an orientation, thanks, sorry .
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…