title: ListView very slow when scrolling (using ViewHolder/recycling)
body: <p>I'm back at trying out some Android dev again. I have an "old" HTC Hero phone lying around, so I booted that one up, did some updates and are now up n running again with Eclipse and the rest.</p>
  
  <p>I have Android 2.1 running on the device.</p>
  
  <p>I have made a very simple test app that doesn't do anything at all except for showing some Activities and such. Even though there is no database connection, no data fetched from any network the app is very slow.</p>
  
  <p>For example, I have a ListView with some custom layout items. When adding only 6-7 items (so that I get the scrolling) it is very slow when scrolling. Also, I have some buttons that changes the Activity and also that is very very slow:</p>
  
  <pre><code>mButtonListenerUPP = new OnClickListener() {
      @Override
      public void onClick(View v)
      {
          Intent myIntent = new Intent(BaseActivity.this, ActivityMain.class);
          BaseActivity.this.startActivity(myIntent);
      }
  };
  </code></pre>
  
  <p>I cannot figure out why.</p>
  
  <p><em>The Adapter, NodeRowAdapter</em></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Context;
  import android.view.*;
  import android.widget.ArrayAdapter;
  
  import android.widget.TextView;
  
  public class NodeRowAdapter extends ArrayAdapter 
  {
      private Activity context;
      private ArrayList&lt;Node&gt; mList;
      private LayoutInflater inflater;
  
      NodeRowAdapter(Activity context, ArrayList&lt;Node&gt; objects) 
      {
          super(context, R.layout.nodepickup, objects);
          this.context=context;
          mList = objects;
          inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      class ViewHolder 
      {
          TextView name;
          TextView time;
          TextView road;
          Node node;
      }
  
      public Node getNode(int position)
      {
          if (mList != null &amp;&amp; mList.size() &gt; position)
              return mList.get(position);
          else
              return null;
      }
      public View getView(int position, View convertView, ViewGroup parent) 
      {
          View view = convertView;
          ViewHolder holder;
          if (view == null)
          {
              view = inflater.inflate(R.layout.nodepickup, parent, false);
              holder = new ViewHolder();
              holder.name =(TextView)view.findViewById(R.id.name);
              holder.time =(TextView)view.findViewById(R.id.time);
              holder.road =(TextView)view.findViewById(R.id.road);
              view.setTag(holder);
          }
          else
          {
              holder = (ViewHolder) convertView.getTag();
          }
  
          Node node = mList.get(position);
          holder.name.setText(node.name);
          holder.time.setText(node.time);
          holder.road.setText(node.road);
  
          return(view);
      }
  }
  </code></pre>
  
  <p><em>The main activity, ActivityMain</em></p>
  
  <pre><code>public class ActivityMain extends BaseActivity 
  {
      private NodeRowAdapter _nodeRowAdapter;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          SICApplication._myContext = this;
          SICApplication._myContext = this;
  
          _nodeRowAdapter = new NodeRowAdapter(this, SICApplication.dataHolder_activityMain._nodes);
          ListView listView1 = (ListView) findViewById(R.id.ListViewNodes);
          listView1.setOnItemClickListener(new OnItemClickListener() 
          {
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) 
              {
                  Node node = _nodeRowAdapter.getNode(position);
                  Log.v("MyApp", "Node=" + node.name);
              } 
          });
          listView1.setAdapter(_nodeRowAdapter);  
  
      }
  
      /* Handles item selections */
      public boolean onOptionsItemSelected(MenuItem item) 
      {
          switch (item.getItemId()) 
          {
              case R.id.add_item:
                  addNodeItem();
                  return true;
          }
          return false;
      }
  
  
  
      private void addNodeItem()
      {
          _nodeRowAdapter.add(new Node("Test", "asd asd ", "14:00", 1));
  
      }
  }
  </code></pre>
  
  <p><em>The custom list item, NodePickup</em></p>
  
  <pre><code>public class NodePickup extends LinearLayout
  {
      public NodePickup(Context context, AttributeSet attributeSet)
      {
          super(context, attributeSet);
  
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          inflater.inflate(R.layout.nodepickup, this);
  
          this.setOnClickListener(new OnClickListener() 
          {
              @Override
              public void onClick(View v)
              {
                  AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                  builder.setMessage("Ajabaja!")
                  .setCancelable(true)
                  .setPositiveButton("JA!", new DialogInterface.OnClickListener() 
                  {
                     public void onClick(DialogInterface dialog, int id) 
                     {
                         dialog.cancel();
                     }
                  });
                  builder.show();
              }
  
          });
      }
  }
  </code></pre>
  
  <p><em>And lastly, the NodePickup XML layout</em></p>
  
  <pre><code>&lt;LinearLayout 
      android:id="@+id/LinearLayout01" 
      android:layout_width="fill_parent" 
      android:layout_height="64dip"
      android:orientation="horizontal" 
      android:background="@drawable/stateful_background"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;ImageView 
          android:id="@+id/ImageView01" 
          android:layout_width="40dip" 
          android:layout_height="40dip"
          android:src="@drawable/arrow_up_green"
          android:background="@android:color/transparent"&gt;
      &lt;/ImageView&gt;
  
      &lt;LinearLayout 
          android:id="@+id/LinearLayout02"
          android:background="@android:color/transparent"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:orientation="vertical"
          xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
          &lt;TextView
              android:text="14:46 (15 min)"
              android:id="@+id/time"
              android:textSize="12dip"
              android:textColor = "#000000"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@android:color/transparent"&gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:text="test"
              android:id="@+id/road"
              android:textSize="12dip"
              android:textColor = "#000000"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@android:color/transparent"&gt;
          &lt;/TextView&gt;
  
          &lt;TextView
              android:text="test test"
              android:id="@+id/name"
              android:textSize="12dip"
              android:textColor = "#000000"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@android:color/transparent"&gt;
          &lt;/TextView&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h2>Update</h2>
  
  <p>If I remove the image in the NodePickup, the lagginess is gone. The question is - why?</p>