Question

I am trying to get it so that when image 1 is showing, a textview shows its name

Here is my array of names

String[] soundcloudDates = { 
    "Image 1", 
    "Image 2", 
    "Image 3", 
    "Image 4",
};

and this is my BaseAdapter using the EcoGallery library from GitHub all of the images scroll correctly but the output for their id is all over the place more often than not it starts printing out position = 1;, then doesn't change until position = 3;

    private class ImageAdapter extends BaseAdapter {
    private Context context;

    ImageAdapter(Context context) {
        this.context = context;
    }

    public int getCount() {
        return 4;
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        // Not using convertView for simplicity. You should probably use it
        // in real application to get better performance.
        ImageView imageView = new ImageView(context);
        int resId;
        switch (position) {
        case 0:
            resId = R.drawable.logo;
                            position = 0;
                            dateView.setText(soundcloudDates[position]);


            break;
        case 1:
            resId = R.drawable.soundcloudtest;
                            position = 0;
                            dateView.setText(soundcloudDates[position]);


            break;
        case 2:
            resId = R.drawable.logo;
                            position = 0;
                            dateView.setText(soundcloudDates[position]);


            break;
        case 3:
            resId = R.drawable.ic_launcher;
                            position = 0;
                            dateView.setText(soundcloudDates[position]);

            break;
        default:
            resId = R.drawable.ic_launcher;
        }
        imageView.setImageResource(resId);
        return imageView;
    }
}

I have tried placing the setText() in different places to no effect.

I dont understand what im doing wrong :( any help would be great

Was it helpful?

Solution

Change these :

 public int getCount() {
    return soundcloudDates.length;
}

public Object getItem(int position) {
    return soundcloudDates[position];
}

public View getView(int position, View convertView, ViewGroup parent) {
    // Not using convertView for simplicity. You should probably use it
    // in real application to get better performance.
    ImageView imageView = new ImageView(context);
    String text = (String) getItem( position );
    int resId;
    switch (position) {
    case 0:
        resId = R.drawable.logo;
            break;
    case 1:
        resId = R.drawable.soundcloudtest;
            break;
    case 2:
        resId = R.drawable.logo;
            break;
    case 3:
        resId = R.drawable.ic_launcher;
            break;
    default:
        resId = R.drawable.ic_launcher;
    }
    dateView.setText(text);
    imageView.setImageResource(resId);
    return imageView;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top