listview跳转到其他活动的片段

时间:2016-01-12 14:45:02

标签: java android listview android-fragments

它应该有替代品吗? 谢谢你的阅读。

1 个答案:

答案 0 :(得分:2)

试试这个:

 lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {

        switch(position)
        case 0:
            Intent myIntent = new Intent(getActivity(), OneActivity.class);
            getActivity().startActivity(myIntent);
            break;
        case 1:
             Intent myIntent = new Intent(getActivity(), OtherActivity.class);
             getActivity().startActivity(myIntent);
             break;            

  }
});