Help listView and onClickListener


Last Updated:

  1. Amon Darthir

    Amon Darthir Active Member This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    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

    Joined:
    Apr 19, 2010
    Messages:
    1
    Likes Received:
    0
    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 This Topic's Starter

    Joined:
    Feb 4, 2010
    Messages:
    27
    Likes Received:
    0
    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...