android - setCardview Background color to match the response that I get from Json -


i make cardview background color match color api provided.

here item_details.xml

    <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:card_view="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <android.support.v7.widget.cardview         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginbottom="0dp"         android:layout_marginleft="5dp"         android:layout_marginright="5dp"         android:layout_margintop="9dp"         card_view:cardcornerradius="3dp"         card_view:cardelevation="0.01dp">          <relativelayout             android:id="@+id/top_layout"             android:layout_width="match_parent"             android:layout_height="160dp">              <imageview                 android:id="@+id/img_thumbnail"                 android:layout_width="match_parent"                 android:layout_height="150dp"                 android:layout_above="@+id/tvmenu"                 android:layout_centerhorizontal="true"                 android:scaletype="fitxy" />              <textview                 android:id="@+id/tvmenu"                 android:layout_width="fill_parent"                 android:layout_height="40dp"                 android:layout_alignparentbottom="true"                 android:layout_alignparentleft="true"                 android:layout_alignparentstart="true"                 android:layout_gravity="bottom"                 android:background="#ff444444"                 android:gravity="center_vertical"                 android:paddingleft="5dp"                 android:paddingright="2dp"                 android:text="test"                 android:textcolor="#fff"                 android:textsize="12sp" />          </relativelayout>     </android.support.v7.widget.cardview> </linearlayout> 

i have 2 parameter in cardview, image , text. basically, color api, gonna set imageview, , details, gonna show in textview.

here api result,

[   {     "name": "item 1",     "colormenu": "#666666"   },   {     "name": "item 2",     "colormenu": "#336699"   },   {     "name": "item 3",     "colormenu": "#663399"   } ] 

i've sucessfully, response "name", , show in cardview. but, when try put in color errors, show up.

com.google.gson.jsonsyntaxexception: java.lang.numberformatexception: invalid double: ""

here onbindviewholder on myadapter

@override  public void onbindviewholder(myviewholder holder, int position) {  holder.mname.settext(itemlist.get(position).getnmmenu());  holder.mcolor.setbackgroundcolor(color.parsecolor(string.valueof(itemlist.get(position).getcolormenu())));      } 

here object

import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname;  public class myobject {  @serializedname("name") @expose private string name; @serializedname("colormenu") @expose private string colormenu;  /** *  * @return * name */ public string getname() { return name; }  /** *  * @param name * name */ public void setname(string name) { this.name = name; }  /** *  * @return * colormenu */ public string getcolormenu() { return colormenu; }  /** *  * @param colormenu * colormenu */ public void setcolormenu(string colormenu) { this.colormenu = colormenu; }  } 

i ended making color first object color in json.

and getting result, , working code

holder.mcolor.setbackgroundcolor(color.parsecolor(itemlist.get(position).getcolormenu())); 

thanks guys help.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -