Guest User

Color.parseColor :(

a guest
Oct 24th, 2013
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1. public class MadListActivity extends ListActivity {
  2.     static final String TAG="MadListActivity";
  3.    
  4.     @Override
  5.     public void onCreate(Bundle savedInstanceState)
  6.     {
  7.         super.onCreate(savedInstanceState);
  8.         //no need of setContentView
  9.         Log.d(TAG,"Parse hardcoded "+Color.parseColor("#ffff45"));
  10.         String[] list=getResources().getStringArray(R.array.menu_array);
  11.         ColouredMenuItem item;
  12.         List<ColouredMenuItem> menuList=new ArrayList<ColouredMenuItem>();
  13.         for(int i=0;i<list.length;i++)
  14.         {
  15.             item=new ColouredMenuItem();
  16.             String[] cmenu =list[i].split("#");
  17.             item.name=cmenu[0];
  18.             item.colour="#"+cmenu[1];
  19.             menuList.add(item);
  20.         }
  21.        
  22.         for(int i=0;i<menuList.size();i++)
  23.         {
  24.             try{
  25.                 Log.d(TAG,""+Color.parseColor((menuList.get(i).colour)));
  26.             }
  27.             catch(NumberFormatException ex)
  28.             {
  29.                 Log.e(TAG, "Failed again");
  30.             }
  31.         }
  32.        
  33.         MadAdapter adapter=new MadAdapter(this,menuList,R.layout.layout_row);
  34.         getListView().setAdapter(adapter);
  35.     }
  36.    
  37. }
  38.  
  39. public class MadAdapter extends BaseAdapter{
  40.  
  41.     static final String TAG="MadAdapter";
  42.     Context context;
  43.     List<ColouredMenuItem> menuList=new ArrayList<ColouredMenuItem>();
  44.     int resourceId;
  45.     LayoutInflater inflater;
  46.     MadAdapter(Context context,List<ColouredMenuItem> list,int resourceId)
  47.     {
  48.         this.context=context;
  49.         this.menuList=list;
  50.         this.resourceId=resourceId;
  51.         inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  52.     }
  53.  
  54. @Override
  55. public int getCount() {
  56.     // TODO Auto-generated method stub
  57.     return menuList.size();
  58. }
  59.  
  60. @Override
  61. public Object getItem(int position) {
  62.     // TODO Auto-generated method stub
  63.     return menuList.get(position);
  64. }
  65.  
  66. @Override
  67. public long getItemId(int position) {
  68.     // TODO Auto-generated method stub
  69.     return menuList.indexOf(menuList.get(position));
  70. }
  71.  
  72. @Override
  73. public View getView(int position, View convertView, ViewGroup parent) {
  74.     // TODO Auto-generated method stub
  75.     View row=convertView;
  76.     TextView textView;
  77.         if(row==null)
  78.         {
  79.             row=inflater.inflate(resourceId, parent, false);
  80.             textView=(TextView)row.findViewById(R.id.text1);
  81.             row.setTag(R.id.text1,textView);
  82.         }
  83.         else
  84.             textView=(TextView)row.getTag(R.id.text1);
  85.    
  86.     try{   
  87.         Log.d(TAG, menuList.get(position).colour);
  88.         textView.setText(menuList.get(position).name);
  89.        
  90.         {
  91.             row.setBackgroundColor(Color.parseColor(menuList.get(position).colour));
  92.         }
  93.     }
  94.     catch(Exception ex)
  95.     {
  96.         Log.e(TAG, "Still does not work");
  97.     }
  98.         return row;
  99.     }
  100. }
  101.  
  102. My Logcat:
  103.  
  104.  Parse hardcoded -187
  105.  Failed again
  106.  Failed again
  107.  Failed again
  108.  Failed again
  109.  #ffffff
  110.  Still does not work
  111.  #ffffBB
  112.  Still does not work
  113.  #fff45f
  114.  Still does not work
  115.  #ffff00
  116.  Still does not work
Advertisement
Add Comment
Please, Sign In to add comment