• Tutorials
  • Tips & Tricks
  • Applications
  • News

Android Trainee

  • Tutorials
  • Tips & Tricks
  • Applications
  • News
Home  /  Tutorials  /  Android Query Image Loader With GridView For Android.
13 July 2015

Android Query Image Loader With GridView For Android.

Written by admin@androidtrainee
Tutorials Android GridView, Android Query, Android Query Image Loader, Aquery, GridView, Image Loader Leave a Comment

Android Query Image Loader With GridView For Android.

 

—>  AndroidManifest.xml


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

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

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />

<application

android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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>

 

–> In Values Folder

 

styles.xml


<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->

</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->

</style>
<style name="ProgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal"/>
</resources>

 

 

IN Layout Folder

activity_main.xml

 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:horizontalSpacing="4dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="4dip"
android:padding="4dip" />

</RelativeLayout>

 

 

item_grid_image.xml

 

 


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dip" >

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="120dip"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />

<ProgressBar
android:id="@+id/progress"
style="@style/ProgressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:indeterminate="false"
android:max="100" />

</FrameLayout>

 

Constants.java

 


package com.example.universalimageloaderdemo;


public final class Constants {

public static final String[] IMAGES = new String[] {
// Heavy images
"http://mobworld.co.in/BestWallpaper/3D/image1.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image2.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image3.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image4.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image5.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image6.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image7.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image8.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image9.jpg",
"http://mobworld.co.in/BestWallpaper/3D/image10.jpg",


};

}

 

MainActivity.java


package com.example.universalimageloaderdemo;

import com.androidquery.AQuery;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;


public class MainActivity extends Activity {

 

GridView grid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

grid = (GridView)findViewById(R.id.grid);
grid.setAdapter(new ImageAdapter(this));
}

private static class ImageAdapter extends BaseAdapter {

private static final String[] IMAGE_URLS = Constants.IMAGES;

private LayoutInflater inflater;
AQuery aq;

ImageAdapter(Context context) {
inflater = LayoutInflater.from(context);
aq = new AQuery(context);

}

@Override
public int getCount() {
return IMAGE_URLS.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.item_grid_image, parent, false);
holder = new ViewHolder();
assert view != null;

holder.imageView = (ImageView) view.findViewById(R.id.image);

view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
aq.id(holder.imageView).progress(view.findViewById(R.id.progress)).image(IMAGE_URLS[position]);
return view;
}
}

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

admin@androidtrainee

 Previous Article Universal Image Loader With GridView For Android.
Next Article   Picasso Image Loader With GridView For Android.

Related Posts

  • Android New Quick Action Animation.

    July 15, 2015
  • Android satellite menu Animation.

    July 15, 2015
  • Android Staggered Grid & List View.

    July 14, 2015

Leave a Reply

Cancel reply

Tags

admob Advertising Networks AerServ Airpush android android ads android Advertising Networks Android App android chart animation Android GridView android L android lollipop androidmapv2 AppBrain AppFlood Appia AppKey Appnext AppOptim Appwiz chart chartview Epom Market google place api GridView Image Loader InMobi LeadBolt location map mapv2 mapv2 api material design Minimob Mobicow MobileCore MobiMicro NativeX Pingjam RevMob StarApplication startapp TapContext touched location Widdit

Count per Day

  • 347Reads yesterday:
  • 463819Total visitors:
  • 39Visitors today:
  • 2412Visitors per month:
  • 1Visitors currently online:
© Copyright 2014. Theme by BloomPixel.
Posting....