GithubHelp home page GithubHelp logo

two-way-gridview's Introduction

TwoWayGridView

An Android GridView that can be configured to scroll horizontally or vertically.

I should have posted this over a year and a half ago, but never got around to it. I needed a grid view that in portrait would scroll vertically, but in landscape, would scroll horizontally. I thought I could try hacking up the Gallery, but that never works out well, and if GridView could really be configured to scroll any direction, it would just be so much easier.

So I built it one weekend. Lots of left, right, top, bottom changes, but the end result is a really useful UI widget.

Feel free to use it in your apps, according to the Apache 2.0 license. Also feel free to fork it and improve it. You could fairly easily create a horizontal listview by extending TwoWayAbsListView

Usage

The TwoWayGridView can be used as a drop-in replacement for the normal Android GridView. It just has a few more configurable attributes:

  • scrollDirectionPortrait (vertical | horizontal) The direction the grid will scroll when the device is in portrait orientation
  • scrollDirectionLandscape (vertical | horizontal) The direction the grid will scroll when the device is in landscape orientation
  • numRows (integer) Number of rows in grid view when in horizontal scrolling mode
  • verticalSpacing (dimension) Height of vertical spacing between grid rows
  • rowHeight (dimension) Height of each grid row

Here is an example from the demo layout where it is configured to scroll vertically in portrait and horizontally in landscape :

<?xml version="1.0" encoding="utf-8"?>
<com.jess.ui.TwoWayGridView
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#E8E8E8"
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    app:cacheColorHint="#E8E8E8"
    app:columnWidth="80dp"
    app:rowHeight="80dp"
    app:numColumns="auto_fit"
    app:numRows="auto_fit"
    app:verticalSpacing="16dp"
    app:horizontalSpacing="16dp"
    app:stretchMode="spacingWidthUniform"
    app:scrollDirectionPortrait="vertical"
    app:scrollDirectionLandscape="horizontal"
    app:gravity="center"/>

two-way-gridview's People

Contributors

flavienlaurent avatar jerrellmardis avatar jess-anders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

two-way-gridview's Issues

Fatal Lint error: onLayout

Hi Jess,
I don't know how to use this library in my project, (copy-pasting the code doesn't feel right). So I tried to add a library module (using git submodule to keep it up-to-date).
However, when I selected "Import existing Eclipse ADT or Gradle project as a module", it asked me for Eclipse installation location (I don't have any).
So I decided to create a build.gradle file (anyway Android is going the Gradle way, whether we want it or not). I had hard time figuring out proper settings, but finally found that someone already did that: https://github.com/AppFellas/TwoWayGridViewGradle/blob/master/build.gradle
So I created a build.gradle file (below), but there's one problem, it throws a fatal Lint error, along with some non-fatal.
Here it is:

WrongCall: Using wrong draw/layout method
../../src/com/jess/ui/TwoWayAdapterView.java:758: Suspicious method call; should probably call "layout" rather than "onLayout"
 755            // Force one here to make sure that the state of the list matches
 756            // the state of the adapter.
 757            if (mDataChanged) {
 758                this.onLayout(false, getLeft(), getTop(), getRight(), getBottom());
 759            }
 760        } else {
Note: This issue has an associated quickfix operation in Android Studio/IntelliJ Fix 
Priority: 6 / 10
Category: Correctness
Severity: Fatal
Explanation: Using wrong draw/layout method.
Custom views typically need to call measure() on their children, not onMeasure. Ditto for onDraw, onLayout, etc.

To reproduce this, go to /lib, place the build.gradle there, and run gradle build. Gradle version is 2.3, though I doubt that matters.

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.2'
    }
}

apply plugin: 'com.android.library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 22
        versionCode 1
        versionName '1.0'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
    // Worakaround for fatal Lint error
    // lintOptions {
    //  abortOnError false
    // }
}

SetDivider

How can I do to have setDivider method that exists on ListView ?
Thank you

Pager Adapter

Hi there, thanks for the great library, works flawlessly.

I am wonder, how i can implement a pager - so it snaps to the view when scrolled?

Thanks

Yellow patch on selecting of an item

Thanks for this helpful library
.
I observed something
.
On click of the item, Yellow patch is seen in the background
Note: I am aware android listview also works similarly but we can disable it android retaining the click but it is not so in case of this library
.
capture

Two-way-gridview with simple cursor adapter jumbles images during update

I use your two-way-gridview (congrats on the simplicity of it by the way) to show a horizontal list of photos my user has taken. The gridview is backed by a simple cursor adapter, and it updates every time the user takes a picture (the photos are in reverse order of creation date). I do use a viewbinder because the picture loading is really slow on the default cursor adapter class.

The problem is that when the photos update, they listview will appear to run the cursor backa nd forth and update the imageviews multiple times. It's very confusing to the user as the imageviews update onces, then again, before re-updating a final time.

Here's the link of what that looks like: http://youtu.be/PZvKeKsQBUE

I'm guessing this is due to some confusion in the manipulation of columns to get the gridview to scroll horizontally - but hopefully there's a way around it? Here are the methods that update the gridview:

String[] from = {MediaStore.Images.ImageColumns.DATA};
        int[] to = {R.id.imageContent};
        TwoWayGridView imageListView = (TwoWayGridView) view.findViewById(R.id.imagelist);
        getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);
        mMediaAdapter = new SimpleCursorAdapter(getActivity(), R.layout.imagelistview, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        mMediaAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                if(view.getId() == R.id.imageContent){
                    BitmapWorkerTask task = new BitmapWorkerTask((ImageView) view, TwitterFragment.this);
                    task.execute(cursor.getString(columnIndex));
                    return true;
                }
                return false;
            }
        });
        imageListView.setAdapter(mMediaAdapter);
    }

 @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        switch(id){
            case CURSOR_LOADER_ID:
                if (args!= null){
                    String filePath = (String) args.get("uri");
                    File temp = new File(filePath);
                    getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(temp)) );
                }
                Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                Uri queryUri = imageUri.buildUpon().appendQueryParameter("limit", "10").build();
                Log.i("THE IMAGE PATH", String.valueOf(MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
                String queryFolder = "%streem%";
                String[] where = new String[]{queryFolder};
                return new CursorLoader(getActivity(), queryUri, null, MediaStore.Images.Media.DATA + " LIKE ? ", new String[]{queryFolder}, MediaStore.Images.ImageColumns.DISPLAY_NAME + " DESC");
            default:
                return null;
        }
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        mMediaAdapter.changeCursor(cursor);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        mMediaAdapter.changeCursor(null);

    }

///This gets called after a photo is successfully taken, so that the gridview can get updated.
 public void updatePhoto(ScreenShot screenShot){
                    if (screenShot != null){
                Bundle bundle = new Bundle();
                bundle.putString("uri", screenShot.getFilePath());
                getLoaderManager().restartLoader(CURSOR_LOADER_ID, bundle, this);
           }
    }


    private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight){
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth){
            final int halfHeight = height /2;
            final int halfWidth = width / 2;

            while ((halfHeight/inSampleSize) > reqHeight
                && (halfWidth / inSampleSize > reqWidth)) {

              inSampleSize *=2;


            }
        }
        return inSampleSize;
    }

    private static Bitmap decodeSampledBitmapFromResource(String filePath, int reqWidth, int reqHeight){
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap file = BitmapFactory.decodeFile(filePath, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(filePath, options);
    }

    class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
        private final WeakReference<ImageView> imageViewReference;
        private int data = 0;
        private String filePath;
        private TwitterFragment activity;



        public BitmapWorkerTask(ImageView imageView, TwitterFragment activity){
            imageViewReference = new WeakReference<ImageView>(imageView);
            this.activity = activity;
        }

        @Override
        protected Bitmap doInBackground(String... params) {
            this.filePath = params[0];
          Bitmap bmp = decodeSampledBitmapFromResource(filePath, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
          return bmp;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap){
            if (imageViewReference != null && bitmap != null){
                final ImageView imageView = imageViewReference.get();
                if (imageView != null){
                    imageView.setImageBitmap(bitmap);
                }
            }
        }
    }


Issues with currently selected items.

It seem like the twowaygridview doesn't handle focus change properly. Take for example the following scenario.

grid layout

Both Alpha and Gamma grid are scrolling horizontally and both only have one row. Pressing UP on the d-pad from Gamma always transfers focus to Alpha-6 (the the last visible item on Alpha). Pressing down from Alpha always sets the focus to Gamma-A.

I've tried using onFocusChangeListeners and calling either setSelection(position) or manually calling the OnItemSelectedListener but both are ignored. Should the default focus not be position 0 on first entry, and the last selected position on re-entry?

0th view never being called

I have made a very simple adapter that extends baseadapter. This adapter simply sets the bg color of a child and sets the title textview of this child to "item i", where i is from 0 to whatever number-mine is 1000. When my app starts, the 0th element is never shown and the last viewable items, say 17 and 18, are both displayed as view 17. When i do Log.d("inside adapter", "Position:"+position) I get the logcat shown below. This tells me that element 0 is null at first, but then something happens before the 0th view is sent to my adapter because the 0th view is never null again. I is passed to the adapter as non-null and hence is not created. I've tried to look at your code but can't figure out why it's not passing my adapter a null view on the 0th element. Could you please look into this as it seems like a bug on your side.

Also, getChildCount() always returns actual count - 1; this may be related.

Many thanks.

11-16 13:20:03.606: D/ActivityThread(7713): setTargetHeapUtilization:0.25
11-16 13:20:03.606: D/ActivityThread(7713): setTargetHeapIdealFree:8388608
11-16 13:20:03.606: D/ActivityThread(7713): setTargetHeapConcurrentStart:2097152
11-16 13:20:03.966: D/2wayLV(7713): Null;Position:0
11-16 13:20:03.996: D/libEGL(7713): loaded /system/lib/egl/libEGL_adreno200.so
11-16 13:20:03.996: D/libEGL(7713): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
11-16 13:20:04.006: D/libEGL(7713): loaded /system/lib/egl/libGLESv2_adreno200.so
11-16 13:20:04.076: I/Adreno200-EGLSUB(7713): ConfigWindowMatch:2087: Format RGBA_8888.
11-16 13:20:04.096: E/(7713): s3dReadConfigFile:75: Can't open file for reading
11-16 13:20:04.106: E/(7713): s3dReadConfigFile:75: Can't open file for reading
11-16 13:20:04.106: D/OpenGLRenderer(7713): Enabling debug mode 0
11-16 13:20:04.106: D/2wayLV(7713): Not Null;Position:0
11-16 13:20:04.106: D/2wayLV(7713): Not Null;Position:0
11-16 13:20:04.106: D/2wayLV(7713): Null;Position:1
11-16 13:20:04.116: D/2wayLV(7713): Null;Position:2
11-16 13:20:04.116: D/2wayLV(7713): Null;Position:3
11-16 13:20:04.116: D/2wayLV(7713): Null;Position:4
11-16 13:20:04.127: D/2wayLV(7713): Null;Position:5
11-16 13:20:04.137: D/2wayLV(7713): Null;Position:6
11-16 13:20:04.137: D/2wayLV(7713): Null;Position:7
11-16 13:20:04.147: D/2wayLV(7713): Null;Position:8
11-16 13:20:04.147: D/2wayLV(7713): Null;Position:9
11-16 13:20:04.167: D/2wayLV(7713): Null;Position:10
11-16 13:20:04.167: D/2wayLV(7713): Null;Position:11
11-16 13:20:04.167: D/2wayLV(7713): Null;Position:12
11-16 13:20:04.177: D/2wayLV(7713): Null;Position:13
11-16 13:20:04.177: D/2wayLV(7713): Null;Position:14
11-16 13:20:04.187: D/2wayLV(7713): Null;Position:15
11-16 13:20:04.187: D/2wayLV(7713): Null;Position:16
11-16 13:20:04.197: D/2wayLV(7713): Null;Position:17
11-16 13:20:04.397: D/2wayLV(7713): Null;Position:0
11-16 13:20:04.407: D/2wayLV(7713): Not Null;Position:17

SetClipToPadding=false causes rows to be removed too soon and added too late.

I was using a transparent ActionBar and had padding so that the gridview started below the ActionBar. Using clip to padding to allow it to scroll through the action bar but when the row entered the action bar it was removed. The same with rows being added and a transparent Nav bar. This behaviour doesn't happen with a normal gridview

Getting runtime exception in the Class TwoWayGridView

I am trying to use two way GridView in my project. I have created my own custom adapter for GridView. When I tried running application, I got following exception :

java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to com.jess.ui.TwoWayAbsListView$LayoutParams
at com.jess.ui.TwoWayGridView$HorizontalGridBuilder.onMeasure(TwoWayGridView.java:2872)

Is it because I am using my own custom adapter?

What kind of license does your project have?

Hi!
I have a library for working with lists (network data loading, pagination, etc) so with standard list it supports your two-way-grid-view library for horizontal lists.

But I didn't find any information about license of this project :( So, what kind of license does your project use?

I got problem with custom adapter

It was function normally with cursoradapter, binding an image view, etc.
But when I changed it to a customadapter (arrayadapter) in first draw it get the height very low, but if I call another activity and come back it draw all fine.
here are 2 screenshots, to visualize what I'm saying:
screenshot_2014-10-22-12-00-34
screenshot_2014-10-22-12-00-44

private methods should be public

int getHeaderViewsCount()
int getFooterViewsCount()

missing implementation of the
mList.addHeaderView(top);
mList.addFooterView(bottom);

app:gravity="fill_vertical" not work

want to grow the vertical size of the object if needed so it completely fills its container, I set the configration app:gravity="fill_vertical" but it seems not work

scroll horizontal grid from code

Hello,

i wonder if its possible to scroll the grid from code,

let me explain this way imagine this is my grid columns

column7 column6 column5 column4 column3 column2 column1

when gridd is shown the focus is on column7 but i want column1 to be focused.
i thought scrolling from code can solve my problem but i couldn't do that,
this problem is driving me crazy for couple of days.

i will appreciate your help.

ScrollBar does not return

It appears when the view is first shown but subsequent scrolling does not reshow the scrollbar.

Tested on Android 4.1+

Create simple vertical textView with horizontal scroll

Hi
My ultimate goal is vertical textView start from top-left ... bottom-left then start new column and go down until it ends. And user can horizontally scroll from left to right to see the last textView. Here is the example.
1 5 9
2 6 10
3 7 11
4 8 12
Then user can click on the number to proceed the choice.
The example provided in the repository is too advanced.
Could you please simplify or give me hint to do my problem?

MainActivity.java


package com.jaikra.sarit.wecare;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;

import TwoWayGridView.TwoWayGridView;

public class MainActivity extends AppCompatActivity {
    static final String[] numbers = new String[] {
            "A", "B", "C", "D", "E",
            "F", "G", "H", "I", "J",
            "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TwoWayGridView gridview = (TwoWayGridView) findViewById(R.id.gridview);
        gridview = (TwoWayGridView) findViewById(R.id.gridview);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, numbers);
        gridview.setAdapter(adapter);

    }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.jaikra.sarit.wecare.MainActivity">


    <include layout="@layout/content_main" />


</android.support.design.widget.CoordinatorLayout>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.jaikra.sarit.wecare.MainActivity"
    tools:showIn="@layout/activity_main">

    <com.jess.ui.TwoWayGridView
        android:background="#E8E8E8"
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:cacheColorHint="#E8E8E8"
        app:columnWidth="80dp"
        app:rowHeight="80dp"
        app:numColumns="auto_fit"
        app:numRows="auto_fit"
        app:verticalSpacing="16dp"
        app:horizontalSpacing="16dp"
        app:stretchMode="spacingWidthUniform"
        app:scrollDirectionPortrait="vertical"
        app:scrollDirectionLandscape="horizontal"
        app:gravity="center"/>
</LinearLayout>

Error:

E/AndroidRuntime: FATAL EXCEPTION: main
                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jaikra.sarit.wecare/com.jaikra.sarit.wecare.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class com.jess.ui.TwoWayGridView
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                                                     at android.app.ActivityThread.access$600(ActivityThread.java:123)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                                                     at android.os.Handler.dispatchMessage(Handler.java:99)
                                                     at android.os.Looper.loop(Looper.java:137)
                                                     at android.app.ActivityThread.main(ActivityThread.java:4424)
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:511)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                                                     at dalvik.system.NativeStart.main(Native Method)
                                                  Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.jess.ui.TwoWayGridView
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                     at com.jaikra.sarit.wecare.MainActivity.onCreate(MainActivity.java:25)
                                                     at android.app.Activity.performCreate(Activity.java:4465)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                     at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                     at android.os.Looper.loop(Looper.java:137) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:511) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                     at dalvik.system.NativeStart.main(Native Method) 
                                                  Caused by: java.lang.ClassNotFoundException: com.jess.ui.TwoWayGridView
                                                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
                                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
                                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 
                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823) 
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:729) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                     at com.jaikra.sarit.wecare.MainActivity.onCreate(MainActivity.java:25) 
                                                     at android.app.Activity.performCreate(Activity.java:4465) 
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                     at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                     at android.os.Looper.loop(Looper.java:137) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:511) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                     at dalvik.system.NativeStart.main(Native Method) 

Got NullPointerException in TextView inside Two-way-gridView

Hi. I want to use TextView inside two-way-gridview.
I can successfully use ArrayAdapter with two-way-gridview. It work correctly as I want.
But when I adapt the example from http://stackoverflow.com/questions/22429829/how-to-add-a-textview-to-a-gridview-in-android.
I got NullPointerException when accessing TextView. Here are my code.

MainActivity.java:

public class MainActivity extends AppCompatActivity {
    static final String[] numbers = new String[] {
            "A", "B", "C", "D", "E",
            "F", "G", "H", "I", "J",
            "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TwoWayGridView gridview = (TwoWayGridView) findViewById(R.id.gridview);
        gridview = (TwoWayGridView) findViewById(R.id.gridview);
//        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//                android.R.layout.simple_list_item_1, numbers);
        TextViewAdapter adapter = (TextViewAdapter) new TextViewAdapter(this, numbers);
        gridview.setAdapter(adapter);
    }
}

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<com.jaikra.sarit.wecare.TwoWayGridView.TwoWayGridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridView1"
    android:numColumns="auto_fit"
    android:gravity="center"
    android:columnWidth="100dp"
    android:stretchMode="columnWidth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

</com.jaikra.sarit.wecare.TwoWayGridView.TwoWayGridView>

item.xml

<TextView
    android:id="@+id/grid_item_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:layout_marginTop="5px"
    android:textSize="15px"
    xmlns:android="http://schemas.android.com/apk/res/android">
</TextView>

Problem:
FATAL EXCEPTION: main java.lang.NullPointerException at com.jaikra.sarit.wecare.TextViewAdapter.getView(TextViewAdapter.java:54)

*Line 54 is : *

            TextView textView = (TextView) gridView
                    .findViewById(R.id.grid_item_label);

Question :
Where am I wrong?

TwoWayGridView.scrollTo(x, y) doesn't work

I have a TwoWayGridView configured to scroll horizontally that I want to scroll programmatically. I tried to call myGridView.scrollTo(0, 0) to see if it scrolls to the beginning of the list, but it doesn't seem to have any effect.

Probably related is that myGridView.getScrollX() and myGridView.getScrollY() always return 0 in the following code:

    final TwoWayGridView myGridView = (TwoWayGridView)view.findViewById(R.id.gridview);
    myGridView.setOnScrollListener(new OnScrollListener() {
        @Override public void onScrollStateChanged(TwoWayAbsListView view, int scrollState) {}
        @Override public void onScroll(TwoWayAbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            myGridView.post(new Runnable() {
                @Override public void run() {
                    Log.i(TAG, "Scrolling to ("+myGridView.getScrollX()+", "+myGridView.getScrollY()+")");
                }
            });
        }
    });

NullPointerException in fillLeft method

Hi,
I have been receiving a few crashes from crashlytics recently in the TwoWayGridView, which I cannot seem to reproduce:
Stacktrace:

java.lang.NullPointerException
at com.jess.ui.TwoWayGridView$HorizontalGridBuilder.fillLeft()
at com.jess.ui.TwoWayGridView$HorizontalGridBuilder.makeAndAddView()
at com.jess.ui.TwoWayGridView.lookForSelectablePosition()
at com.jess.ui.TwoWayAbsListView$HorizontalTouchHandler.getFlingRunnable()
at com.jess.ui.TwoWayAbsListView$HorizontalTouchHandler$HorizontalFlingRunnable.run()
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5306)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)

Problem with Android-Query and Adapter

Hi,
I'm using Android-Query library to async load the image into my ImageView in my adapter.

When I use:
if (aq.shouldDelay(position, convertView, parent, url)) {
aq.id(holder.image).image(placeholder, 1.0f);
} else {
aq.id(holder.image).image(url, true, true, 200, 0, null, 0, 1.0f);
}

I've this error:
java.lang.ClassCastException: com.jess.ui.TwoWayGridView cannot be cast to android.widget.AbsListView

Anyone can help me?

vertical scroll not work in Landscape

I test something

app:scrollDirectionLandscape="horizontal"
app:scrollDirectionPortrait="horizontal"
app:scrollDirectionPortrait="vertical"

  • These work as I set property.

app:scrollDirectionLandscape="vertical"

  • But it doesn't
    There's noting any move when parent is scrollView in Landscape.
    Isn't it supported things or bug?

Linking next and previous buttons

I tried to use smoothScrollToPosition or setSelection.
The problem is that smoothScrollToPosition only works when the offset is greater than 1,
If setSelection returns to 0 position, the UI is broken.

Please help me if I am wrong.

Item placement is 3 * 3 per screen and scrolls horizontally.
ex) setSelection(pageOffset > 0 ? 10 : 1);

How can i place the first item in center of screen?

Hi,

I am trying to place the first visible item at the center of the screen.
The grid view itself fills the entire screen. What i want is some initial margin to make the items start at centerX. (without clipping).

Is this possible?

Failed to instantiate one or more class in my xml

<com.jess.ui.TwoWayGridView android:id="@+id/gridviewForBOSTItem"
android:layout_width="fill_parent"
android:layout_height="50.0dip"
android:layout_toRightOf="@+id/back"
android:background="@null"
android:listSelector="@null"
android:scrollbars="none"
android:visibility="gone"
app:columnWidth="80.0dip"
app:gravity="center"
app:horizontalSpacing="10.0dip"
app:numColumns="auto_fit"
app:numRows="auto_fit"
app:rowHeight="80.0dip"
app:scrollDirectionLandscape="horizontal"
app:scrollDirectionPortrait="horizontal"
app:stretchMode="spacingWidthUniform"
app:verticalSpacing="10.0dip" />

Children are not gaining focus

Only the TwoWayGridView itself is ever gaining focus. Focus to the children is never done. The currently selected item is always being set, but when navigating with a D-PAD focus is never set to the child that is selected. This causes issues when you are using a selectors that act differently when using the focus attributes.

Tutorial recommendation

Hello,
First off, thank you for a great library.

While it's great, it took me a while to get the row and column sizing correct using xml and so I ignored those values and programatically set them in the java code. Since I had so much trouble using the library initially, I wrote an app showing how to make a vertical and horizontal gridview. I also wrote a tutorial explaining how to install the library, how to get spacing down, and how to prevent the gridview from creating a new view for each object-it did so whenever convertView's layout params were set.

The tutorial is at:
http://spragucm.wordpress.com/2013/11/17/android-horizontal-and-vertical-gridview-tutorial/

If you like the tutorial and example, could you post it along with this library in order to help others better use the library and avoid the same frustrations in the future?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.