java - add another layout to this layout while jsonarray exist -
im trying create timeline feed
mean tango newsfeed
json array this:
{"salam":[{"matn":"something","user_esm":"some name","user_image":"image url","liked":1,"followed":0,"user_id":"hfgdlerm"},{"matn":"something 2","user_esm":"other name","user_image":"iamge url","liked":1,"followed":0,"user_id":"hfgdlerm",}
and custom layout like:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <textview android:layout_width="wrap_content" android:layout_height="124dp" android:text="new text" android:id="@+id/textview3" android:layout_weight="0.24" /> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageview" android:minheight="50dp" android:minwidth="50dp" /> </linearlayout>
and home.java default layout this:
public class home extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home); sharedpreferences pref = getapplicationcontext().getsharedpreferences("userpref", 0); sharedpreferences.editor editor = pref.edit(); string useridnow = pref.getstring("userid", null); if(useridnow == null) { intent = new intent(home.this,mainactivity.class); home.this.startactivity(i); } new getfeed(home.this,useridnow).execute(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_home, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } } class getfeed extends asynctask<void, void, string> { private string userid; private context context; relativelayout rellay; public getfeed(context context, string userid) { this.userid = userid; this.context = context; } @override protected string doinbackground(void... voids) { try{ httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://fb.facenegah.com/android/showfeed.php"); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(6); namevaluepairs.add(new basicnamevaluepair("feedid","0")); namevaluepairs.add(new basicnamevaluepair("limit", "1")); namevaluepairs.add(new basicnamevaluepair("userid", userid)); namevaluepairs.add(new basicnamevaluepair("uper", "0")); namevaluepairs.add(new basicnamevaluepair("downer", "0")); namevaluepairs.add(new basicnamevaluepair("isprofile", "0")); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); string responsetext = entityutils.tostring(entity); return responsetext; } catch(exception ex) { } return null; } @override protected void onpostexecute(string s) { super.onpostexecute(s); jsonobject jsonresponse; //toast.maketext(context, "json: "+s, toast.length_short).show(); try { arraylist<string> temp = new arraylist<string>(); jsonresponse = new jsonobject(s); jsonarray movies = jsonresponse.getjsonarray("salam"); for(int i=0;i<movies.length();i++){ jsonobject movie = movies.getjsonobject(i); string characters = movie.getstring("user_esm"); toast.maketext(context, "json: "+characters , toast.length_long).show(); layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(r.layout.rowlayout, null); textview textview = (textview) rowview.findviewbyid(r.id.textview3); imageview imageview = (imageview) rowview.findviewbyid(r.id.imageview); textview.settext(characters); //setlistadapter(rowview); // final listview listview = (listview) rowview.findviewbyid(r.id.listview); } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
i dont know how use custom layout , full textview , imageview while json array exist , show them on home activity timeline
try setadapter , otherthing ... not work
please me this
Comments
Post a Comment