如何把该activity的 position传递到下一个 activity 使用?
intent.putExtra("pst" , position1);
MainActivity 中 getIntent().getIntExtra("pst", 0); //0 为默认值
很基础的东西
通过Intent传,Intent的key最好定义成常量,要不然很容易写乱出错
图片看不到,,
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
curpostion = position;
}
});
private int curpostion = -1;
private final static String POS = "POSTION";
private void startNextActivity(Context context, Class<?> cls){
Intent intent = new Intent(context,cls);
Bundle bundle = new Bundle();
bundle.putInt(POS,curpostion);
intent.putExtras(bundle);
context.startActivity(intent);
}
//下一个Activity中
private int get_postion (){
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
int postion = bundle.get(xxxx.POS); // xxxx你定义常量的类名
return postion;
}
int postion = bundle.getInt(xxxx.POS);