views:

25

answers:

1

Hi,

I have create a list view within a tab with a list of teams within it, I want to create a activity which when clich goes to another class, I want to do this with 20 items that will be in thisa list, code is below

public class ll2 extends ListActivity {

static final String[] teams = new String[] {"Accrington Stanley", "Aldershot", "Barnet", "Bradford City", "Burton Albion", "Bury", "Cheltenham Town", "Chesterfield", "Crewe Alexandra" };

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

final String[] TEAMS = getResources().getStringArray(R.array.twoteams_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, TEAMS));

ListView lv = getListView(); lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();

Intent intent;

intent = new Intent().setClass(this, Bradford.class);

}

}); }

}

I have been messing around with intent but all the tutorials I tried do not mention intent in relation to making a clickable listview.

How can I achieve this

+1  A: 

You'll probably want to override the onListItemClick method in your ListActivity. Based on the position, you will construct an appropriate intent.

@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
    if (position == appropriate_condition) {
        Intent intent = new Intent(this, Bradford.class);
        startActivity(intent);
    }
}

If you need to access data associated with the item, the documentation provides this suggestion:

Subclasses can call getListView().getItemAtPosition(position) if they need to access the data associated with the selected item.

Brian
Thank you so muck I getting close but I'm getting multiple marker errors on View v comma after v comma after position and ) after id is there something I need to remove or a specific place the code should go?
JonniBravo
Could you provide more details and specific error messages?
Brian