Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MadListActivity extends ListActivity {
- static final String TAG="MadListActivity";
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- //no need of setContentView
- Log.d(TAG,"Parse hardcoded "+Color.parseColor("#ffff45"));
- String[] list=getResources().getStringArray(R.array.menu_array);
- ColouredMenuItem item;
- List<ColouredMenuItem> menuList=new ArrayList<ColouredMenuItem>();
- for(int i=0;i<list.length;i++)
- {
- item=new ColouredMenuItem();
- String[] cmenu =list[i].split("#");
- item.name=cmenu[0];
- item.colour="#"+cmenu[1];
- menuList.add(item);
- }
- for(int i=0;i<menuList.size();i++)
- {
- try{
- Log.d(TAG,""+Color.parseColor((menuList.get(i).colour)));
- }
- catch(NumberFormatException ex)
- {
- Log.e(TAG, "Failed again");
- }
- }
- MadAdapter adapter=new MadAdapter(this,menuList,R.layout.layout_row);
- getListView().setAdapter(adapter);
- }
- }
- public class MadAdapter extends BaseAdapter{
- static final String TAG="MadAdapter";
- Context context;
- List<ColouredMenuItem> menuList=new ArrayList<ColouredMenuItem>();
- int resourceId;
- LayoutInflater inflater;
- MadAdapter(Context context,List<ColouredMenuItem> list,int resourceId)
- {
- this.context=context;
- this.menuList=list;
- this.resourceId=resourceId;
- inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- }
- @Override
- public int getCount() {
- // TODO Auto-generated method stub
- return menuList.size();
- }
- @Override
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return menuList.get(position);
- }
- @Override
- public long getItemId(int position) {
- // TODO Auto-generated method stub
- return menuList.indexOf(menuList.get(position));
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- View row=convertView;
- TextView textView;
- if(row==null)
- {
- row=inflater.inflate(resourceId, parent, false);
- textView=(TextView)row.findViewById(R.id.text1);
- row.setTag(R.id.text1,textView);
- }
- else
- textView=(TextView)row.getTag(R.id.text1);
- try{
- Log.d(TAG, menuList.get(position).colour);
- textView.setText(menuList.get(position).name);
- {
- row.setBackgroundColor(Color.parseColor(menuList.get(position).colour));
- }
- }
- catch(Exception ex)
- {
- Log.e(TAG, "Still does not work");
- }
- return row;
- }
- }
- My Logcat:
- Parse hardcoded -187
- Failed again
- Failed again
- Failed again
- Failed again
- #ffffff
- Still does not work
- #ffffBB
- Still does not work
- #fff45f
- Still does not work
- #ffff00
- Still does not work
Advertisement
Add Comment
Please, Sign In to add comment