Android set style rule of parent element based on child element value -


given layout named rellayoutwrap.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/relativelayout1"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >     <textview         android:id="@+id/priorityview"         android:layout_width="50dip"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/statuscheckbox"         android:layout_alignparentright="true"         android:layout_aligntop="@+id/statuslabel" >    </textview> </relativelayout> 

i apply different background color relative layout parent element based on value of textview element.

the value of textview element can change inflate/recycle view. ie.:

layoutinflater inflater = (layoutinflater) mcontext.getsystemservice( context.layout_inflater_service ); relativelayout itemlayout = (relativelayout) inflater.inflate(r.layout.rellayoutwrap,null); final textview priorityview = (textview) itemlayout.findviewbyid(r.id.priorityview);  priorityview.settext("yes");  //or "no" 

so if value of textview "yes" want relativelayouts background color yellow, , if "no" background color blue. possible purely through xml style rules? or have manually set background color value changes programmatically?

honestly, best way set color yourself.

as far know, there isn't way xml, in conditionally check text , change color based on text. possibly have 2 different xmls button , go way, doesn't seem needed here.

in code, have similar this, except have lot more things change color. me, this...

public static final int status_code_yes = 1; public static final int status_code_no = 2;  . . .   if(something something) {     //i need set state yes!     updatetextview(status_code_yes); } else {     //i need set state no...     updatetextview(status_code_no); }  . . .    public void updatetextview(int status) { switch(status) {     case status_code_yes:         textview.settext("yes");         textview.setbackground(color.yellow);         //a lot more stuff here         break;     case status_code_no:          textview.settext("no");         textview.setbackground(color.blue);         //a lot more stuff here         break;      default:         system.out.println("you did wrong here...error");         break; } 

this system works me. technically, guess there ways through xml, don't apply situation.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -