Add Custom Layout to ListView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Add Custom Layout to ListView

Postby TheBigCheese » Sat Nov 28, 2009 11:56 pm

I'm trying to add an icon to each element of a ListView, here's what I've got so far:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MainEntry extends Activity {      
  2.  
  3.         private ArrayList<LinearLayout> posts = new ArrayList<LinearLayout>();
  4.  
  5.         private ListView list;
  6.  
  7.  
  8.  
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.  
  11.         super.onCreate(savedInstanceState);
  12.  
  13.        
  14.  
  15.         LinearLayout rootView = new LinearLayout(this);
  16.  
  17.        
  18.  
  19.         LinearLayout tempView = new LinearLayout(this);
  20.  
  21.        
  22.  
  23.         ImageView icon = new ImageView(this);
  24.  
  25.         icon.setImageResource(R.drawable.wolfire);
  26.  
  27.         tempView.addView(icon);
  28.  
  29.        
  30.  
  31.         posts.add(tempView);
  32.  
  33.        
  34.  
  35.         list = new ListView(this);
  36.  
  37.         list.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  38.  
  39.         list.setAdapter(new ArrayAdapter<LinearLayout>(this,R.layout.post_obj, posts));
  40.  
  41.        
  42.  
  43.         TextView test = new TextView(this);
  44.  
  45.         test.setText("hey");
  46.  
  47.        
  48.  
  49.         rootView.addView(list);
  50.  
  51.        
  52.  
  53.         setContentView(rootView);
  54.  
  55.        
  56.  
  57.        
  58.  
  59.     }  
  60.  
  61. }
  62.  
  63.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


What would I need to put in my custom layout .xml so that depending on a condition from the .java, it would use one of two images for an item in the list?

Thanks.
User avatar
TheBigCheese
Developer
Developer
 
Posts: 26
Joined: Thu Nov 26, 2009 2:31 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests