Android Picasso Fragment Pic from URL -
i've got problem load pic url fragment picasso. when start app it's start without errors pic not loading. app has 1 mainactivity , 3 fragments. below paste xml of mainlayout , 1 fragment class. best me scenario: when user click button on fragment three(red on image), pic load url imageview located on fragment 2 (yellow on image) above of fragment three. please help
package testowy.com.testowyfragment2; import android.app.activity; import android.app.fragment; import android.content.context; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.imageview; import com.squareup.picasso.picasso; /** * created administrator on 2015-07-04. */ public class klasadown extends fragment { private klasadownlistener listener; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragmentdown, container, false); imageview img = (imageview) view.findviewbyid(r.id.imgvv); context c = getactivity().getapplicationcontext(); picasso.with(c).load("http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg") .fit().into(img); view.onclicklistener clicklistener = new view.onclicklistener() { public void onclick(view v) { switch (v.getid()) { case r.id.btnmenu: updatetext("menu"); setimage(); break; case r.id.btnkontakt: updatetext("kontakt"); break; default: break; } } }; button btnmenu = (button) view.findviewbyid(r.id.btnmenu); button btnkontakt = (button) view.findviewbyid(r.id.btnkontakt); btnkontakt.setonclicklistener(clicklistener); btnmenu.setonclicklistener(clicklistener); return view; } public interface klasadownlistener { public void onitemselected(string txt); } private void updatetext(string txt) { listener.onitemselected(txt); } public void setimage() { imageview img = (imageview) getview().findviewbyid(r.id.imgvv); picasso.with(getactivity().getapplicationcontext()).load("http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg").into(img); } @override public void onattach(activity activity) { super.onattach(activity); if (activity instanceof klasadownlistener) { listener = (klasadownlistener) activity; } else { throw new classcastexception(activity.tostring() + " musi implementowa� interfejs: overviewfragment.overviewfragmentactivitylistener"); } } } <linearlayout 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" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity"> <fragment android:id="@+id/fragmentup" class="testowy.com.testowyfragment2.klasaup" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="5"> </fragment> <fragment android:id="@+id/fragmentcenter" class="testowy.com.testowyfragment2.klasacenter" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3"> </fragment> <fragment android:id="@+id/fragmetdown" class="testowy.com.testowyfragment2.klasadown" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3"> </fragment> </linearlayout> package testowy.com.testowyfragment2; import android.app.fragment; import android.os.bundle; import android.support.annotation.nullable; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; /** * created administrator on 2015-07-04. */ public class klasacenter extends fragment { @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater .inflate(r.layout.fragmentcenter, container, false); return view; } public void settext(string txt){ textview view = (textview) getview().findviewbyid(r.id.fragmentcentertext); view.settext(txt); } } package testowy.com.testowyfragment2; import android.app.activity; import android.os.bundle; import android.widget.imageview; import com.squareup.picasso.picasso; public class mainactivity extends activity implements klasadown.klasadownlistener{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public void onitemselected(string txt) { klasacenter fragment = (klasacenter) getfragmentmanager() .findfragmentbyid(r.id.fragmentcenter); // sprawdzamy czy fragment istnieje w tej aktywno�ci if (fragment != null && fragment.isinlayout()) { // ustawiamy teskt fragmencie fragment.settext(txt); imageview img = (imageview) findviewbyid(r.id.imgv); picasso.with(this).load("http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg").fit().into(img); } } }
it's stupid forget add internet permission:)
<uses-permission android:name="android.permission.internet"></uses-permission>
now ok!
Comments
Post a Comment