问题
I asked a question about ui updating in preferencelistfragment in android.(How to change imageview background color in a preference in android?)
And it works for android 4.1.2 version. I test it also in 2.3.3, 3.0 and 4.3 android versions and i see that it is not working in these versions. To make question simple, i would like to ask why the code below is not working on these versions:
public class SettingsIncomingSearchFragment extends PreferenceListFragment
implements SharedPreferences.OnSharedPreferenceChangeListener
{
@Override
public void onCreate(Bundle icicle)
{
<!-- other codes -->
setBackgroundColor() ;
<!-- other codes -->
}
private void setBackgroundColor() {
// TODO Auto-generated method stub
LinearLayout mainlayout ;
LinearLayout sublayout ;
View view ;
ImageView img ;
SharedPreferences sp ;
sp = ctx.getSharedPreferences(SHARED_PREFS_NAME, ctx.MODE_PRIVATE);
LayoutInflater inflater = (LayoutInflater)
getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.rectangle_layout, null);
mainlayout = (LinearLayout)view.findViewById(R.id.rectangle_main_layout_ll);
sublayout = (LinearLayout)mainlayout.findViewById(R.id.rectangle_layout_ll);
String defValue = null ;
defValue = sp.getString("incomingsearchbackgroundcolor", String.valueOf(Color.BLACK));
if(defValue != null)
{
img = (ImageView)sublayout.findViewById(R.id.iv_priority);
img.setBackgroundColor(Integer.parseInt(defValue));
}
}
Thanks!
来源:https://stackoverflow.com/questions/21360959/imageview-setbackgroundcolor-is-not-working-in-android