我需要使用意图将值从 1.java 的 onItemClick 方法传递到 2.Java 中的 onActivityResult
1.java
public void onItemClick(AdapterView<?> parent, View view, int position,long id)
{
int songindex=position;
Intent intent2 = new Intent(this, Play.class);
intent2.putExtra("songindex",songindex);
setResult(100, intent2);
startActivity(intent2);
}
2.java
public class Play extends Activity {
MediaPlayer mp;
int currentsong=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
currentsong=getIntent().getIntExtra("songindex",-1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==100)
{
//Intent intent1=getIntent();
//currentsong=getIntent().getExtras().getInt("songindex");
pl(currentsong);
}
}
我的问题是意图值未从 1.java 传递到 2.java,当单击 onItemClick 时,我需要使用意图传递值并调用方法 pl(songindex)