我一直在搜寻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);
             }
        };
}

最佳答案

不应该是:

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

关于java - 如何使可启动新 Activity 的ListView项可点击,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31891227/

10-11 19:57