我是android开发的初学者。这是我的列表图像代码。它不会将图像传递给另一个活动。为什么它不传递图像另一个活动。任何人都可以修复它吗?
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.row, parent, false);
TextView textview = (TextView) row.findViewById(R.id.tvTop);
ImageView imageview = (ImageView) row.findViewById(R.id.list_image);
textview.setText(data_topText[position]);
imageview.setImageResource(data_image[position]);
row.setOnClickListener(new OnClickListener() {
public void onClick(View row) {
TextView textview = (TextView) row.findViewById(R.id.tvTop);
ImageView imageview = (ImageView) row.findViewById(R.id.list_image);
String product = textview.getText().toString();
int images = imageview.getId();
Intent i = new Intent(getApplicationContext(),
SecondScreenActivity.class);
i.putExtra("name", product);
i.putExtra("zurag", images);
startActivity(i);
}
});
return (row);
}
这是 SecondScreenActivity.java:
public class SecondScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
TextView txtName = (TextView) findViewById(R.id.txtName);
ImageView images = (ImageView) findViewById(R.id.image);
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int pic =intent.getIntExtra("zurag", 0);
txtName.setText(name);
images.setImageResource(pic);
}
}