Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.Integer cannot be cast to com.felipecsl.asymmetricgridview.library.model.AsymmetricItem #74

Open
milsun opened this issue Jan 13, 2018 · 3 comments

Comments

@milsun
Copy link

milsun commented Jan 13, 2018

I am trying to use AsymmetricGridView to implement 3 column view of images; but could not get it to work. Throws me the error mentioned.
Here is my code:

public class HomeActivity extends AppCompatActivity {

private AsymmetricGridView listView;
private ImageAdapter adapter;

private Cursor cursor;
/*
 * Column index for the Thumbnails Image IDs.
 */
private int columnIndex;

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    listView = (AsymmetricGridView) findViewById(R.id.listView);

    // Choose your own preferred column width
    listView.setRequestedColumnWidth(dpToPx(120, this));
    listView.setAllowReordering(true);

    // Set up an array of the Thumbnail Image ID column we want
    String[] projection = {MediaStore.Images.Thumbnails._ID};
    // Create the cursor pointing to the SDCard
    cursor = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection, // Which columns to return
            null,       // Return all rows
            null,
            MediaStore.Images.Thumbnails._ID);
    // Get the column index of the Thumbnails Image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);


    final List<AsymmetricItem> items = new ArrayList<>();

    // initialize your items array
    adapter = new ImageAdapter(this);
    AsymmetricGridViewAdapter asymmetricAdapter =
            new AsymmetricGridViewAdapter<>(this, listView, adapter);
    listView.setAdapter(asymmetricAdapter);

    // Set up a click listener
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            // Get the data location of the image
            String[] projection = {MediaStore.Images.Media.DATA};
            cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    projection, // Which columns to return
                    null,       // Return all rows
                    null,
                    null);
            columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToPosition(position);
            // Get image filename
            String imagePath = cursor.getString(columnIndex);
            // Use this path to do further processing, i.e. full screen display

            //Indent for passing string file path to edit activity
        }
    });

}

/**
 * Adapter for our image files.
 */
private class ImageAdapter extends BaseAdapter {
    private Context context;

    public ImageAdapter(Context localContext) {
        context = localContext;
    }

    public int getCount() {
        return cursor.getCount();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView picturesView;
        if (convertView == null) {
            picturesView = new ImageView(context);
            // Move cursor to current position
            cursor.moveToPosition(position);
            // Get the current value for the requested column
            int imageID = cursor.getInt(columnIndex);
            // Set the content of the image based on the provided URI
            picturesView.setImageURI(Uri.withAppendedPath(
                    MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
        } else {
            picturesView = (ImageView) convertView;
        }
        return picturesView;
    }
}
@haris15
Copy link

haris15 commented May 3, 2018

same problem here do you find any solutions ?

@Avalin
Copy link

Avalin commented May 9, 2018

I'm having the same problem

@harisf3
Copy link

harisf3 commented Mar 19, 2019

any luck to this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants