How to set the adapter to twolinelist Android-ThrowExceptions

Exception or error:

I am trying to use the TwoLineListItem, and my class is not extending the ListActivity, but just the Activity class.

the layout file is shown below;

     <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/seealllayout"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:padding="10dip">
  <TwoLineListItem
     android:id="@+id/SeeAllList"
     android:paddingTop="2dip"
     android:paddingBottom="2dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:mode="oneLine"
  >
     <TextView
    android:id="@android:id/text1"
    android:gravity="left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dip"
    android:layout_marginTop="6dip"
    android:textAppearance="?android:attr/textAppearanceLarge"
    />
    <TextView
    android:id="@android:id/text2"
    android:gravity="right"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dip"
    android:layout_marginTop="6dip"
    android:layout_marginRight="6dip"
    android:layout_toRightOf="@android:id/text1"
    android:textAppearance="?android:attr/textAppearanceLarge"
     />
        </TwoLineListItem>
    <Button
       android:id="@+id/close"
       android:layout_marginTop="10dp"
       android:layout_gravity="center_horizontal"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/cclose" />
       </LinearLayout>

In the class I have the data loading into the simpleAdapter without any problem, but I am not able to find a way to now connect this data to the view twolistitem. If I uncomment the mlist definition, the app hangs..

public class SeeAllActivity extends Activity {
  private SimpleAdapter sa; 

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // open our layout and set the titles
    setContentView(R.layout.seeall_layout);

    Resources res = getResources();
    String[] unitsarr = null;
    String[] factorsarr = null;

    factorsarr = res.getStringArray(R.array.anglefactor_array);
    unitsarr = res.getStringArray(R.array.angleunits_array);

    ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

    HashMap<String,String> item;
    for(int i=0;i<factorsarr.length;i++){
      item = new HashMap<String,String>();
      item.put( "line1", unitsarr[i]);
      item.put( "line2", factorsarr[i]);
      list.add( item );
    }   

    sa = new SimpleAdapter(this, list,
        android.R.layout.two_line_list_item,
            new String[] { "line1","line2" },
            new int[] {android.R.id.text1, android.R.id.text2});

     //ListView mListView = (ListView) findViewById(R.id.SeeAllList);
     //mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.seeall2_layout, sa));
     //mListView.setAdapter(sa);

        // putting a listener to the close button
        Button close = (Button) findViewById(R.id.close);
        close.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        finish();
    }
     });
  }
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *