Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:48:20+00:00 2026-05-30T23:48:20+00:00

I have I problem with my custom GridView. I wrote the custom GridViewClass to

  • 0

I have I problem with my custom GridView. I wrote the custom GridViewClass to enable the fling gesture within the GridView. However, there are some errors I don’t quite understand.

My code:

<pl.flamis.GestureGridView
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:numColumns="7"
            android:id="@+id/calendar" 
            android:listSelector="#00000000" 
            android:layoutAnimation="@anim/wave_scale"
            android:background="#c5c5c7" >
</pl.flamis.GestureGridView>

the custom GridView class:

public class GestureGridView extends GridView {

private GestureDetector gd;



public GestureGridView(final Context context, AttributeSet attrs) {
    super(context);
    gd = new GestureDetector(context,
                    new GestureDetector.OnGestureListener() {

                            @Override
                            public boolean onSingleTapUp(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                            }

                            @Override
                            public void onShowPress(MotionEvent e) {
                                    // TODO Auto-generated method stub

                            }

                            @Override
                            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                                            float distanceY) {
                                    // TODO Auto-generated method stub
                                    return false;
                            }

                            @Override
                            public void onLongPress(MotionEvent e) {
                                    // TODO Auto-generated method stub

                            }

                            @Override
                            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                                            float velocityY) {
                                    return false;
                            }

                            @Override
                            public boolean onDown(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                            }
                    });
}


@Override
public boolean onTouchEvent(MotionEvent event) {
    gd.onTouchEvent(event);
    return true;
}

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    return gd.onTouchEvent(ev); 
}

}

the main class code:

public class Kalendarz extends Activity implements OnGestureListener{

//Grid data
public static GestureGridView calendar;
private static CellAdapter cell_adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    myGesture = new GestureDetector(this);

    context = getApplicationContext();

    res = getResources();

    Notes = new Notes();
    tble = new Timetable(Notes);

    MDate = new MonthData(tble.getDay(), tble.schift_sys );


    setContentView(R.layout.kalendarz);

  if(tble.schift_sys == -1)
    showDialog(sys_zmian);

  Button next = (Button) findViewById(R.id.next_month);
  next.setOnClickListener(
      new OnClickListener(){
          @Override
          public void onClick(View v) {
              tble.goNextMonth();

              updateDateInfo();

              for(int i=0; i< calendar.getChildCount(); i++){
                  CellButton b = ((CellButton)((LinearLayout)calendar.getChildAt(i)).getChildAt(0));
                  if(i >= tble.getFday()-1 && i < tble.getFday() -1 + tble.getNodays()){
                      b.setText(String.valueOf(i-tble.getFday()+2));
                  }else{
                      b.setText("-1");
                  }
              }

              findViewById(R.id.calendar).invalidate();

              ((GestureGridView)findViewById(R.id.calendar)).startLayoutAnimation();
          }
      }
  );

  Button prev = (Button) findViewById(R.id.previous_month);
  prev.setOnClickListener(
      new OnClickListener(){
          @Override
          public void onClick(View v) {
              tble.goPrevMonth();

              updateDateInfo();

              for(int i=0; i< calendar.getChildCount(); i++){
                  CellButton b = ((CellButton)((LinearLayout)calendar.getChildAt(i)).getChildAt(0));
                  if(i >= tble.getFday()-1 && i < tble.getFday() -1 + tble.getNodays()){
                      b.setText(String.valueOf(i-tble.getFday()+2));
                  }else{
                      b.setText("-1");
                  }
              }

              findViewById(R.id.calendar).invalidate();

              ((GestureGridView)findViewById(R.id.calendar)).startLayoutAnimation();
          }
      }
  );


  GridView day_names = (GridView)findViewById(R.id.day_names);
  day_names.setAdapter( new ArrayAdapter <CharSequence> (
                                this, 
                                R.layout.day_names_element,
                                res.getStringArray(R.array.days)
                            )
                     );


  calendar = (GestureGridView)findViewById(R.id.calendar);
  cell_adapter = new CellAdapter(this);
  calendar.setAdapter(cell_adapter);

  updateDateInfo();

  /*Intent j = new Intent(this, Service.class);
  startService(j);*/
}

public class CellAdapter extends BaseAdapter{

    Context MyContext;

    public CellAdapter(Context _MyContext) {
        MyContext = _MyContext; 
    }

    @Override
    public int getCount() {
        return 6*7;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View MyView = convertView;
         if ( convertView == null ){
            //Inflate the layout
            LayoutInflater li = getLayoutInflater();
            MyView = li.inflate(R.layout.cell_calendar_element, null);

            Button b = (Button)MyView.findViewById(R.id.cellbutton);
            registerForContextMenu(b);

         }

         Button b = (Button)MyView.findViewById(R.id.cellbutton);
         if(position >= tble.getFday()-2 && position < tble.getFday()-1 + tble.getNodays()){
             b.setText(String.valueOf(position-tble.getFday()+2));
         }else{
             b.setText("0");
         }

         return MyView;
    }
}

public void updateDateInfo(){
    TextView date_info = (TextView)findViewById(R.id.date_info);
    CharSequence months[] = res.getTextArray(R.array.miesiace);
    date_info.setText(months[tble.getDay().getMM()-1].toString()+" "+tble.getDay().getYYYY());
}

@Override
public boolean onDown(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    // TODO Auto-generated method stub
    try {
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
            return false;
        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            Button b1 = (Button)findViewById(R.id.next_month);
            b1.performClick();
        }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            Button b2 = (Button)findViewById(R.id.previous_month);
            b2.performClick();
        }
        return true;
    } catch (Exception e) {
        // nothing
        Toast.makeText(getApplicationContext(), "left", Toast.LENGTH_LONG).show();
    }
    return false;
}

@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub

}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event){
    return myGesture.onTouchEvent(event);
}

}

and the error code:

03-02 16:30:27.301: E/AndroidRuntime(2132): FATAL EXCEPTION: main
03-02 16:30:27.301: E/AndroidRuntime(2132): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.flamis/pl.flamis.Kalendarz}: java.lang.NullPointerException
03-02 16:30:27.301: E/AndroidRuntime(2132):     at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.os.Looper.loop(Looper.java:123)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.ActivityThread.main(ActivityThread.java:3647)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at java.lang.reflect.Method.invoke(Method.java:507)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at dalvik.system.NativeStart.main(Native Method)
03-02 16:30:27.301: E/AndroidRuntime(2132): Caused by: java.lang.NullPointerException
03-02 16:30:27.301: E/AndroidRuntime(2132):     at pl.flamis.Kalendarz.onCreate(Kalendarz.java:304)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-02 16:30:27.301: E/AndroidRuntime(2132):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
03-02 16:30:27.301: E/AndroidRuntime(2132):     ... 11 more

I’ve spent over a day trying different solutions and nothing seems to work. I will appreciate any help. Thanks in advance!

EDIT: I attached the source code of the main class – if I change all the GestureGridView to GridView – it works like a charm, BUT fling does not work on the GridView – however it works on the rest of the layout. I need to make it work on the GridView too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:48:21+00:00Added an answer on May 30, 2026 at 11:48 pm

    I actually found another solution, because the way I tried to do it simply didn’t work and nobody knows why. I used GestureOverlayView instead, and it works great. Just had to add two swipe gestures to the gesture library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem sorting my Gridview using my custom entity classes My complex entity
I have an android gridview which i'm using some custom scrolling going on in,
After posting this: Custom Header in GridView ...I have a related problem. I have
I seem to have a problem with getting MVC to fill in my custom
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I have a custom Jabber IM client and I'm having a problem with links.
My problem is similar to Django Passing Custom Form Parameters to Formset Ive have
I have designed a custom section handler before but I'm faced with a problem
Begining with JSP and servlet development, I have some problems with a bodyless custom
I have problem in some JavaScript that I am writing where the Switch statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.