title: Performance Optimization ListView
body: <p>That's my class and layouts..
  testlayout dot java</p>
  
  <pre><code>package com.example.project1;
  import android.app.ListActivity;
  public class testLayout extends ListActivity 
  {
          Project1 mAct; 
          void setNewWindow()
  {
      mAct=Project1.getMAct(); //Project1 context (Project1 - MainActivity)
      mAct.setContentView(R.layout.testlayout);
      String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
      "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
      "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
      "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
      "Android", "iPhone", "WindowsMobile" };
      setListAdapter(new MyPerformanceArrayAdapter(mAct, values));
  }
  }
  </code></pre>
  
  <p>testlayout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;ListView
      android:id="@+id/listView2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true" &gt;
  &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>MyPerformanceArrayAdapter.java</p>
  
  <pre><code>package com.example.project1;
  
  import android.app.Activity;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class MyPerformanceArrayAdapter extends ArrayAdapter&lt;String&gt; {
        private final Project1 context1;
        private final String[] names1;
  
        static class ViewHolder {
          public TextView text;
          public ImageView image;
        }
  
        public MyPerformanceArrayAdapter(Project1 context, String[] names) {
          super(Project1.getMAct(), R.layout.rowlayout, names);
          context1 = Project1.getMAct();
          names1 = names;
          Log.v("4", "GOOD");
  
        }
  
  
  
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
          View rowView = convertView;
          Log.v("3", "GOOD");
  
          // reuse views
          if (rowView == null) {
            LayoutInflater inflater = Project1.getMAct().getLayoutInflater();
            rowView = inflater.inflate(R.layout.rowlayout, null);
            // configure view holder
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.text = (TextView) rowView.findViewById(R.id.label);
            viewHolder.image = (ImageView) rowView.findViewById(R.id.icon);
            rowView.setTag(viewHolder);
          }
  
          // fill data
          ViewHolder holder = (ViewHolder) rowView.getTag();
          String s = names1[position];
          holder.text.setText(s);
          Log.v("2", "GOOD");
  
          if (s.startsWith("Windows7") || s.startsWith("iPhone")
              || s.startsWith("Solaris")) {
            holder.image.setImageResource(R.drawable.no);
          } else {
            holder.image.setImageResource(R.drawable.ok);
          }
          Log.v("1", "GOOD");
  
          return rowView;
        }
      } 
  </code></pre>
  
  <p>rowlayout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
  
      &lt;ImageView
          android:id="@+id/icon"
          android:layout_width="22px"
          android:layout_height="22px"
          android:layout_marginLeft="4px"
          android:layout_marginRight="10px"
          android:layout_marginTop="4px"
          android:layout_weight="21.23"
          android:src="@drawable/ic_launcher" /&gt;
  
      &lt;TextView
          android:id="@+id/label"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@+id/label"
          android:textSize="20px" /&gt;
  
      &lt;ListView
          android:id="@+id/listView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="21.23" &gt;
      &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and ERROR's</p>
  
  <pre><code> at android.app.Activity.getSystemService(Activity.java:4410)
      FATAL EXCEPTION: main
      java.lang.NullPointerException
      at android.app.Activity.setContentView(Activity.java:1867)
      at android.app.ListActivity.ensureList(ListActivity.java:312)
      at android.app.ListActivity.setListAdapter(ListActivity.java:263)
      at com.example.project1.testLayout.setNewWindow(testLayout.java:19)
      at com.example.project1.SecondLayout$2.onClick(SecondLayout.java:65)
  </code></pre>
  
  <p>What's Wrong??? </p>
  
  <p>That's My SecondView.java</p>
  
  <pre><code>package com.example.project1;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  public class SecondLayout 
  {
  private static Project1 mAct;   
  testLayout tL= new testLayout();
  
  
  public void setNewWindow()
  {
      mAct = Project1.getMAct();
      mAct.setContentView(R.layout.secondlayout); 
      TextView textView1 = (TextView) mAct.findViewById(R.id.textView4);
      TextView textView2 = (TextView) mAct.findViewById(R.id.textView5);
      ResClass res = Project1.getMAct().getRes();
      textView1.setText(res.getV1("status"));
      textView2.setText(res.getV1(2,"posts", "author"));
      int len= res.getLen();
      List&lt;Map&lt;String, String&gt;&gt; arList = new ArrayList&lt;Map&lt;String,String&gt;&gt;();
      for (int i=0; i&lt;len; i++)
      {
          Map &lt;String, String&gt; resMap = new HashMap &lt;String, String&gt;();
          resMap.put("authors", res.getV1(i, "posts", "author"));
          resMap.put("titles", res.getV1(i, "posts", "title"));
          arList.add(resMap);
      }
      ListView listView1= (ListView) mAct.findViewById(R.id.listView1);
  
      SimpleAdapter adp = new SimpleAdapter (mAct, arList,         android.R.layout.simple_list_item_2, new String[] {"authors","titles"}, new int[]         {android.R.id.text1, android.R.id.text2});
  
      listView1.setAdapter(adp);
  
  
  
      res.resFree();
      Button button1 = (Button) mAct.findViewById(R.id.button4);
      Button button2 = (Button) mAct.findViewById(R.id.button5);
  
  
      button1.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              mAct.StartWindow();
          }
      });
  
      button2.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              Log.v("ON CLICK", "GOOD");
              tL.setNewWindow();
          }
      });
  
  
  
  }
  
  }
  </code></pre>
  
  <p>Project1 is my MainActivity.java class
  I'm calling TestLayout аfrom SecondLayout 
  getMAct - give's Project1 prj1= this;</p>
  
  <pre><code>public static Project1 getMAct()
  {
  return prj1;
  }
  </code></pre>