-1

i wanted to use UIL for one of my projects so i just made this prototype project to see how the library works. I built it according to the sample project from https://github.com/nostra13/Android-Universal-Image-Loader. But when i run the proj the images are not shown and the logcat doesn't show any errors as well. I just get a blank white screen with project name in the title bar.Can anybody tell me whats wrong in my code.Any help is gratefully accepted.

public class GridGallery extends Activity {
DisplayImageOptions options;
GridView listView;
String[] imageUrls = new String[] { "drawable://" + R.drawable.img1,
        "drawable://" + R.drawable.img2, "drawable://" + R.drawable.img3,
        "drawable://" + R.drawable.img4, "drawable://" + R.drawable.img5,
        "drawable://" + R.drawable.img6, "drawable://" + R.drawable.img7,
        "drawable://" + R.drawable.img8, "drawable://" + R.drawable.img9,
        "drawable://" + R.drawable.img10, "drawable://" + R.drawable.img11 };
public static final int INDEX = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            this).build();
    ImageLoader.getInstance().init(config);
    options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_stub)
            .showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
            .cacheOnDisk(true).considerExifParams(true)
            .bitmapConfig(Bitmap.Config.RGB_565).build();
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.image_grid, container, false);
    listView = (GridView) rootView.findViewById(R.id.grid);
    ((GridView) listView).setAdapter(new ImageAdapter());
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            startImagePagerActivity(position);
        }
    });
    return rootView;

}

protected void startImagePagerActivity(int position) {

    // Intent intent = new Intent(getActivity(), SimpleImageActivity.class);
    // intent.putExtra(Constants.Extra.FRAGMENT_INDEX,
    // ImagePagerFragment.INDEX);
    // intent.putExtra(Constants.Extra.IMAGE_POSITION, position);
    // startActivity(intent);
}

public class ImageAdapter extends BaseAdapter {

    private LayoutInflater inflater;

    ImageAdapter() {
        inflater = LayoutInflater.from(getApplicationContext());
    }

    @Override
    public int getCount() {
        return imageUrls.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        View view = convertView;
        if (view == null) {
            view = inflater
                    .inflate(R.layout.image_grid_item, parent, false);
            holder = new ViewHolder();
            assert view != null;
            holder.imageView = (ImageView) view.findViewById(R.id.image);
            holder.progressBar = (ProgressBar) view
                    .findViewById(R.id.progress);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        ImageLoader.getInstance().displayImage(imageUrls[position],
                holder.imageView, options,
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        holder.progressBar.setProgress(0);
                        holder.progressBar.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                            FailReason failReason) {
                        holder.progressBar.setVisibility(View.GONE);
                    }

                    @Override
                    public void onLoadingComplete(String imageUri,
                            View view, Bitmap loadedImage) {
                        holder.progressBar.setVisibility(View.GONE);
                    }
                }, new ImageLoadingProgressListener() {
                    @Override
                    public void onProgressUpdate(String imageUri,
                            View view, int current, int total) {
                        holder.progressBar.setProgress(Math.round(100.0f
                                * current / total));
                    }
                });

        return view;
    }

}

static class ViewHolder {
    ImageView imageView;
    ProgressBar progressBar;
}
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.imagetester"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".GridGallery"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
Clinton Dsouza
  • 330
  • 4
  • 20

1 Answers1

0

Its because you forget to add the items in your onCreateView to your grid view's adapter. You must add the items manually after you set the gridview's adapter.

Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
  • could you please tell me what items.i compared it to the sample proj and its the same code.nothing diff – Clinton Dsouza Nov 01 '14 at 11:54
  • @ClintonDsouza you should check again, the "imageUrls" has not been used, and the fact is your adapter is empty because you dont put anything inside it hence the listview is empty. – Blaze Tama Nov 01 '14 at 12:01