【问题标题】:How to make a clickable by item ListView that starts a new activity如何使启动新活动的项目ListView可点击
【发布时间】:2015-10-31 16:41:06
【问题描述】:

我已经在 youtube 上搜索了几个小时,但似乎找不到一个有效的。到目前为止,我的代码中有这个,但它不会让我开始一个新的活动。

public class MainActivity extends ActionBarActivity {
ArrayList<PerMoney> PeepList = new ArrayList<PerMoney>();
int pos = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ListView people = (ListView)findViewById(R.id.peopleList);
    setContentView(R.layout.activity_main);
    if(PeepList.size() != 0)
        UpdateList();
    people.setOnItemClickListener(onListClick);
}

然后这里是 onitemclick 部分

private AdapterView.OnClickListener onListClick=new AdapterView.OnItemClickListener()
{
        ListView people = (ListView) findViewById(R.id.peopleList);
        int res;
        people.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override

             public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
             {
                   pos = position;
                   Intent intent = new Intent(this,SecondActivity.class);
                   startActivityForResult(intent, 0);
             }
        };
}

【问题讨论】:

标签: java android android-studio


【解决方案1】:

不应该是:

Intent intent = new Intent(MainActivity.this,SecondActivity.class);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多