从列表视图启动的活动 [英] Start an activity from a listview

查看:111
本文介绍了从列表视图启动的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个列表视图,我试图通过启动从列表视图活动{startActivity(class.java);}

Hi I have a listview and I am trying to start an activity from the listview by {startActivity(class.java);}

进口android.app.Activity; 进口android.os.Bundle; 进口android.view.View; 进口android.widget.AdapterView; 进口android.widget.ArrayAdapter; 进口android.widget.ListView;

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView;

public class ll2 extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String[] myList = 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"};              
        ListView lv = new ListView(this);
        lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,myList));
        setContentView(lv); }

        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

        if ("Bradford City".equals(MyList()[position]))
        {startActivity(Bradford.java);}
   }
}

我得到一个错误这一行,如果(布拉德福德.equals(MYLIST()[位置]))方法myList中()是未定义的类型[112

I am getting a error with this line if ("Bradford City".equals(MyList()[position])) method myList() is undefined for the type ll2

我已经试过的方法ALLSORTS,我不能得到任何工作。所有我想要做的是列表中的每个球队都有一个单独的Java文件(类)随着他们的活动,帮助我在我束手无策。

I have tried allsorts of methods and I cannot get anything to work. All I want to do is for each team in the list have a separate java file(Class) With activities in them, Help I'm at my wits end.

推荐答案

MYLIST()[位置] myList上[位置]
接下来,您不能启动这样一个活动 startActivity(Bradford.java); 。为了启动一个新的活动,你需要创建和意图,然后设置活动类。然后,你可以调用startActivity与意图

MyList()[position] should be myList[position].
Next you can not start an activity like this startActivity(Bradford.java);. For starting a new activity you need to create and intent and then set the Activity class. Then you can call startActivity with that intent.

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

和需要布拉德福德活动添加到您的清单,以及

And you need to add Bradford activity to your manifest as well.

这篇关于从列表视图启动的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆