0

我有一个ListView,在这个ListView我有字符串数组。我想设置ActionListener这个ListView,但我不知道,也许是按索引查找。Activity当用户单击其中一个时,我必须转到下一个新的ListItems

这就是我已经拥有的:

final ListView listview = (ListView) getActivity().findViewById(R.id.listview2); 
final ReadSubjectSelectionListAdapter adapter = new ReadSubjectSelectionListAdapter(getActivity(), subject);
listview.setAdapter(adapter);

和:

public void loadSubjects(){
  subject = new String[11]; 
    for(int i=0; i<11; i++){ 
      subject[i] = new String();
    }

  subject[0]=("Math"); 
  subject[1]=("Kaz history"); 
  subject[2]=("Kaz language"); 
  subject[3]=("Rus language"); 
  subject[4]=("Eng language");
  subject[5]=("Physics"); 
  subject[6]=("Chemistry"); 
  subject[7]=("Biology"); 
  subject[8]=("Geography"); 
  subject[9]=("World history"); 
  subject[10]=("Kaz literature");
}
4

2 回答 2

0

你需要使用这样的东西:

myListview.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
{
  public void onItemSelected(AdapterView parentView, View childView, int pos, long id) 
  {
    Intentintent = new Intent(CurrentActivity.this, NewActivity.class);
    intent.putExtra("position",pos);    
    startActivity(intent);
  }
});
于 2013-07-24T12:35:41.160 回答
-1
myListview.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
{
  public void onItemSelected(AdapterView parentView, View childView, int pos, long id) 
  {
    Intentintent = new Intent(CurrentActivity.this, NewActivity.class);
    intent.putExtra("position",pos);    
    startActivity(intent);
  }
});

在清单文件中添加权限

 <activity android:name=".NewActivity" />
于 2013-07-24T12:39:37.683 回答