VIẾT MỘT ỨNG DỤNG GALLERY CHO ANDROID VỚI GLIDE

Menu chính

LearningAndroidPHPGraphic DesignPhotoshopCác chuyên mụckhácCơ sở dữliệuĐồ họa máytínhMạng sản phẩm tínhXử lý đa chiềuPC Trouble ShootingThủ thuật ExcelJoomLaCác kỹ năng cầnthiếtKỹ năng họctậpKỹ năng làmviệcKỹ năng giaotiếpKỹ năng làm cho việcnhómTử vi bóitoánZodiac – 12 cung hoàngđạoTình yêu và cuộcsống

*
Nhip sống trẻ

An error has occurred; the feed is probably down. Try again later.

avatar


Hi allIn this tutorial I will show you how to get an image from your phone gallery & show it in an imageview.Here we use intents to open up the image gallery and get the image URI.Here I am setting the image type as “image” khổng lồ get only the images.And on onActivityResult if the result is OK, then get the data using getData() function and converting the imageURI lớn the stringPath.Then show the image in the imageview using setImageURI.


*

Hi all ……..

Ofter we have trouble with loading continous images in ANDROID from our application directory.The reason is that all resources have a quality resource ID which we need to get khổng lồ load these resources.The following example shows how khổng lồ get these unique identifier from the “path” of the resource.For example Here I have seven images with names sample_0.png, sample_1.png lớn sample_7.png.By usingimgID = getResources().getIdentifier(“sample_”+num, “drawable”, “com.switchImages”);I convert the path khổng lồ it’s identifier.Note that all these images need khổng lồ be in “drawable” folder.Even if your folder name is “drawable-hdpi” also then give only “drawable” và third parameter the packagename.Just copy và paste the following code to lớn your java file.Make sure that you have all the images in the resource.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.switchImages;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class Switch extends Activity
ImageView img;
Button preview;
int num = 0;
public int imgID = 0;
Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView)findViewById(R.id.imageView);
preview = (Button)findViewById(R.id.Prev);
try

imgID = getResources().getIdentifier("https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgsample_"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg+num, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgdrawable"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgcom.switchImages"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg);
img.setImageResource(imgID);
catch(Exception e)
Toast.makeText(Switch.this,e.getMessage() , Toast.LENGTH_SHORT).show();

preview.setOnClickListener(new OnClickListener()
Override
public void onClick(View v)
imgID = getID();
switchImage(imgID);

);

public void switchImage(int ID)
try

ID = getResources().getIdentifier("https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgsample_"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg+num, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgdrawable"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgcom.switchImages"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg);
img.setImageResource(ID);
catch(Exception e)
Toast.makeText(Switch.this,e.getMessage() , Toast.LENGTH_SHORT).show();


public int getID()
int imgID = 0;
num++;
if(num > 7) num = 0;
try

imgID = getResources().getIdentifier("https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgsample_"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg+num, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgdrawable"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg, "https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpgcom.switchImages"https://tienkiemkyduyen.mobi/get-image-from-gallery-android/imager_7_30590_700.jpg);
catch(Exception e)
Toast.makeText(Switch.this,e.getMessage(), Toast.LENGTH_SHORT).show();

return imgID;


Share this:


Like this:


Like Loading...

Leave a Reply


Enter your phản hồi here...

Fill in your details below or click an icon khổng lồ log in:


*

Email (required) (Address never made public)
Name (required)
Website
*

You are commenting using your tienkiemkyduyen.mobi.com account.(LogOut/Change)


*

You are commenting using your Google account.(LogOut/Change)


*

You are commenting using your Twitter account.(LogOut/Change)


*

You are commenting using your Facebook account.(LogOut/Change)


Cancel

Connecting khổng lồ %s


Notify me of new comments via email.

Notify me of new posts via email.


Δ


This site uses Akismet lớn reduce spam. Learn how your comment data is processed.


Lưu Trữ

Lưu TrữSelect CategoryBan tin cong nghe(8)Cà phê cuối tuần(34)Design(1)Ebook(2)funny clip(15)Funny story(28)Khoa hoc(7)Meo vat(3)Music(82)Nghệ thuật sống(56)Organization(17)public(20)Song khoe-lam dep(21)Stories(72)Truyen teo tich(2)Truyen cuoi(32)Tình Yêu với Cuộc Sống(46)Tử vi(183)Thủ Thuật mạng internet – Mạng(11)Thủ thuật Phần cứng(5)Thủ thuật Phần mềm(16)Thu thuat tienkiemkyduyen.mobi(2)Thư viện hình(3)welcome(1)

Recent Posts


Create a free website or blog at tienkiemkyduyen.mobi.com. WP Designer.


FollowFollowing
Sign me up
Send to e-mail AddressYour NameYour thư điện tử Address
*
Cancel
Post was not sent - kiểm tra your email addresses!
Email kiểm tra failed, please try again
Sorry, your blog cannot mô tả posts by email.
%d bloggers lượt thích this:

Leave a Reply

Your email address will not be published. Required fields are marked *