Integer[] leftItems = new Integer[]{R.drawable.ic_1, R.drawable.ic_2, R.drawable.ic_3, R.drawable.ic_4, R.drawable.ic_5};
Integer[] rightItems = new Integer[]{R.drawable.ic_6, R.drawable.ic_7, R.drawable.ic_8, R.drawable.ic_9, R.drawable.ic_10};
leftAdapter = new ItemsAdapter(this, R.layout.item, leftItems);
rightAdapter = new ItemsAdapter(this, R.layout.item, rightItems);
listViewLeft.setAdapter(leftAdapter);
listViewRight.setAdapter(rightAdapter);
leftViewsHeights = new int[leftItems.length];
rightViewsHeights = new int[rightItems.length];
对于 leftlist 视图 onclick 我使用下面的代码
listViewLeft.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Integer name = (Integer) arg0.getItemAtPosition(arg2);
Intent Courses = new Intent(ItemsActivity.this, ViewMyImage.class);
Courses.putExtra("position",arg2);
Courses.putExtra("name",name.toString());
startActivity(Courses);
}
});
在 ViewMyImage.java 我使用这个代码来获取值
int value = getIntent().getExtras().getInt("position");
String name = getIntent().getExtras().getString("name");
Toast.makeText(getApplicationContext(), name,Toast.LENGTH_LONG).show();
我想要图像 ic_X 的值,我可以再次显示图像。