التعديل على كود جافا اندرويد
banner
2018-10-02 , 04:12 مساءً
arafa’s Avatar
arafa

عضو جديد

المشاركات:2
التسجيل:Sep 2007
arafa
السلام عليكم ورحمه الله

اخوانى الاعزاء لدى كود اريد ان اقوم بالتعديل عليه ليقوم بقراءه امتداد معين من موقع على الانترنت ولكن يحدث خطأ فى هذا السطر:

img.setImageDrawable(res.getDrawable(res.getIdentifier("com.almaistro.tyre.android:drawable/" + app.getIcon(), null, null)));

لانى اريدة ان يكون كالتالى :

img.setImageDrawable(res.getDrawable(res.getIdentifier("http://www.website.com/image/" + app.getIcon(), null, null)));

وعندا يحدث الخطأ ويغلق التطبيق
الكود :

[CODE]
public View getView(int position, View convertView, ViewGroup parent) {
2. View v = convertView;
3. if (v == null) {
4. v = LayoutInflater.from(getContext()).inflate(R.layout.app_offers, null);
5. }
6. Application app = (Application) this.items.get(position);
7. if (app != null) {
8. ImageView img = (ImageView) v.findViewById(R.id.appIcon);
9. TextView titleText = (TextView) v.findViewById(R.id.title);
10. TextView dateText = (TextView) v.findViewById(R.id.sdate);
11. if (img != null) {
12. Resources res = getContext().getResources();
13. img.setImageDrawable(res.getDrawable(res.getIdentifier("com.arafa.android:drawable/" + app.getIcon(), null, null)));
14. }
15. if (titleText != null) {
16. titleText.setText(app.getSubject());
17. }
18. if (dateText != null) {
19. dateText.setText(app.getDate());
20. }
21. }
22. return v;

[/CODE]
Enlarged Image
2018-10-02 , 04:12 مساءً
2018-10-02 , 06:35 مساءً
just smile’s Avatar
just smile

فعال

المشاركات:1451
التسجيل:Nov 2005
just smile
اعتقد لازم تحول الصورة اول الى Bitmap

ممكن تشوف الخطأ بالتفصيل في الrun console اذا انت تستخدم الاندرويد استديو

صعب معرفة السبب بدون معلومات عن الخطا
2018-10-02 , 06:35 مساءً
2018-10-03 , 12:03 صباحاً
arafa’s Avatar
arafa

عضو جديد

المشاركات:2
التسجيل:Sep 2007
arafa
اخى الفاضل اشكرك على محاولة المساعدة منك

باختصار شديد كيف لى ان اجعل الكود بهذا الشكل :

[CODE]
if(img != null) {
Resources res = getContext().getResources();
String sIcon = "https://arafa4.000webhostapp.com/system/" + app.getIcon();
img.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
[/CODE]
2018-10-03 , 12:03 صباحاً
2018-10-03 , 06:49 صباحاً
xphp’s Avatar
xphp

بارز

المشاركات:1636
التسجيل:Feb 2009
xphp
عزيزي

أنت تحاول تستخدم دالة getDrawable لتحميل صورة من الانترنت لكن الدالة لا تعمل بهذا الشكل. ألدالة هذه ترجع لك ملف من مجلد الDrawables في المشروع ( ما ينفع تحمل من النت باستخدامها)

اذا أردت تحميل الصورة من النت لها طريقة مختلفة لكن عشان تريح نفسك استخدم مكتبة زي مثلا Picasso فيها كل الي تحتاجه
2018-10-03 , 06:49 صباحاً