在Listview中更改类的方法

时间:2010-09-23 16:37:05

标签: java android eclipse

我创建了一个带有四个标签的标签式视图,并将四个列表视图附加到标签页。我已经创建了包含列表视图的单独类,现在我想在列表视图中添加一个活动

public class l2 extends ListActivity {

/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // Create an array of Strings, that will be put to our ListActivity
    String[] names = new String[] { "Accrington Stanley", "Aldershot Town", "Barnet", "Bradford City", "Burton Albion", "Bury", "Cheltenham Town", "Chesterfield", "Crewe A", "Gillingham", "Hereford Utd", "Lincoln City", "Macclesfield T", "Morecombe", "Northampton T", "Oxford Utd", "Port Vale", "Rotherham Utd", "Shrewsbury T", "Southend Utd", "Stevenage", "Stockport C", "Torquay Utd", "Wycombe W"};
    // Create an ArrayAdapter, that will actually make the Strings above
    // appear in the ListView
    this.setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_checked, names));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    names = new intent().setClass(this, Bradford.class);
    // Get the item that was clicked
    Object o = this.getListAdapter().getItem(position);
    String keyword = o.toString();
    Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
            .show();

}

我在listview中有24个团队,我已经为每个团队创建了一个类,但是我怎样才能创建它,以便当用户选择列表中的团队时,它会转到有问题的类,即bury,bradfdord accrington等.......?

我应该使用什么方法以及如何实现它。 在此先感谢

1 个答案:

答案 0 :(得分:0)

如果我理解正确

你可以使用startACtivity(名字);