Help listView and onClickListener

Discussion in 'Application Development' started by Amon Darthir, Apr 7, 2010.

  1. Amon Darthir

    Amon Darthir Active Member
    15

    Feb 4, 2010
    27
    0
    15
    ok so here is what i have so far

    package
    list.view;

    import
    android.app.ListActivity;

    import
    android.os.Bundle;

    import
    android.view.View;

    import
    android.widget.ArrayAdapter;

    public
    class ListView extends ListActivity {
    /** Called when the activity is first created. */

    @Override

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


    setListAdapter(
    new ArrayAdapter<String>(this,
    android.R.layout.
    simple_list_item_1, ANIONS));
    }

    public static final String[] ANIONS = new String[] {
    "Acetate", "Bromine", "Carbonate", "Chlorate", "Chloride",
    "Chlorite", "Chromate", "Cyanide", "Dychromate",
    };

    protected void onListItemClick(ListView l, View v, int position,long id)
    {

    if (position == 0){
    setContentView(R.layout.
    acetate);
    };
    if (position == 1){
    setContentView(R.layout.
    bromine);
    };
    if (position == 2){
    setContentView(R.layout.
    carbonate);
    };
    }

    }



    now im guessing that there is something wrong with this because whenever i click on an item in the list nothing happens. anyone know how to fix this or what im doing wrond? thanks.
     

    Advertisement
  2. AshBandicoot

    AshBandicoot New Member
    5

    Apr 19, 2010
    1
    0
    5
    Student
    Manchester/Bangor
    try this;
    Code (Text):
    1. public class ListView implements OnClickListener {
    2. }
    and further down the public void OnClick stubs.

    Ash
     
  3. Amon Darthir

    Amon Darthir Active Member
    15

    Feb 4, 2010
    27
    0
    15
    It could just be me, could be that I dont know how to properly add the code, but im not having any luck. Will try a bit more. Thanks though.
     

Share This Page

Loading...