I wrote the following code but I am sure that I did something wrong in the method onItemClick() My listview is displaying properly and when clicked upon another activity opens I
You should write onListItemClick()
like this
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(MainActivity.this,
ImageActivity.class);
intent.putExtra("img", images1[position]);
startActivity(intent);
}
});
ImageActivity.java
public class ImageActivity extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.images);
ImageView iv = (ImageView) findViewById(R.id.imageView2);
iv.setImageResource(getIntent().getIntExtra("img", 0));
}
}
OUTPUT :
here you didnt define any location of your image. define the location string and put in the file and check it.
String location="storage/img1.jpg";
File imgfile = new File(location);