2013-08-01 168 views
0

我擁有電子ArrayAdapter以使電子CustomListView ......這裏是完整的代碼...我想從Java代碼中設置XML R.layout.streampage_custom_row_view的背景顏色務實....任何幫助,請以編程方式更改自定義ListView的顏色?

  adapter = new ArrayAdapter<String>(StreamPage_modified.this, 
        R.layout.streampage_custom_row_view, R.id.title, targetArray) { 


       @Override 
       public View getView(int position, View convertView, ViewGroup parent) { 
        View row = super.getView(position, convertView, parent); 


        TextView Description = (TextView) row 
          .findViewById(R.id.description); 

        Log.d("SPOC COUNT", "" + SPOC.size()); 
        Log.d("SPOC POSitiON", "" + position); 

        Description.setText(SPOC.get(position).getDescription()); 

        return row; 
       } 

      }; 
      adapter.notifyDataSetChanged(); 
      list.setAdapter(adapter); 
      list.setOnItemClickListener(StreamPage_modified.this); 

回答

0

,如果你想set the background color of ListView's row不是試圖row.setBackgroundColor(Color.RED); //(或任何顏色)內getView()

所以你的代碼應該是

 @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      View row = super.getView(position, convertView, parent); 
      row.setBackgroundColor(Color.RED); // or any color 

      TextView Description = (TextView) row 
        .findViewById(R.id.description); 

      Log.d("SPOC COUNT", "" + SPOC.size()); 
      Log.d("SPOC POSitiON", "" + position); 

      Description.setText(SPOC.get(position).getDescription()); 

      return row; 
     } 
相關問題