开发者

how to show images in grid view?

I have a database which contains list of im开发者_StackOverflowage path. My problem is I have to show all the images in a grid view. I have taken list of path from database but i am not able to show all the images in grid layout. Please help me. Thanks


In gridview setAdapter() as you normally do for custom ListView by extending BaseAdapter and passing the arraylist of paths to this adapter class.

Now in getView() method of Adapter add following lines

Bitmap mBitmap = BitmapFactory.decodeFile(path);
mView.setImageBitmapReset(mBitmap, 0, true);

where mView is an ImageView and path will be fetched from arraaylist that you pass to adapter


public class MainActivity extends Activity {
    String[] prgmNameList = {"Grid_1", "Grid_1", "Grid_1"};
    int[] prgmImages = new int[] {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher};

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Gridimageadapter gpa = new Gridimageadapter(MainActivity.this, prgmNameList, prgmImages);
        GridView gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(gpa);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜