My app needs to have multiple ListViews that when an option is clicked, will open a second activity that displays a zoomable picture. Everything in my code compiles, opens correct picture and zooms accordingly. However, the "names" on my list do not appear correctly and all say the same thing: "com.example.poweruser.fcemsandroid.obstetric". Anyone have a solution to correcting this? My code is below:
final Context context = getApplicationContext();
//list contains image name, image location
final List<imagedisplay> myImageList = new ArrayList<imagedisplay>();
myImageList.add(new imagedisplay("Aspirin", R.drawable.aspirin));
myImageList.add(new imagedisplay("Drug2", R.drawable.ekghomepic));
myImageList.add(new imagedisplay("Drug3", R.drawable.aspirin));
myImageList.add(new imagedisplay("Drug4", R.drawable.ekghomepic));
//define ListView and create onItemClick Listener
listview = (ListView) findViewById(R.id.obstetriclistview);
ArrayAdapter<imagedisplay> arrayAdapters = new ArrayAdapter<imagedisplay>(this, R.layout.support_simple_spinner_dropdown_item, myImageList);
listview.setAdapter(arrayAdapters);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent myIntent = new Intent(context, imagedisplay.class);
myIntent.putExtra("name", myImageList.get(position).getName());
myIntent.putExtra("imagePath", myImageList.get(position).getPath());
startActivityForResult(myIntent, 0);
}
});
}}
public class ImageDisplay {
private String Name;
private int Path; // use String if you use a path, in here i'm storing image in drawable
public ImageDisplay(){}
public ImageDisplay(String name, int path){
this.Name = name;
this.Path = path;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public int getPath() {
return Path;
}
public void setPath(int path) {
this.Path = path;
}
}
The second activity code is below:
public class imagedisplay extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagedisplay);
ImageView imageView = (ImageView) findViewById(R.id.imageView3);
Intent myItent = getIntent();
String Name = myItent.getStringExtra("name"); //Do whatever you need with image title
int Path = myItent.getIntExtra("imagePath", 0); //pass this to ImageView
imageView.setImageResource(Path);
TouchImageView img = new TouchImageView(this);
img.setImageResource(Path);
img.setMaxZoom(4f);
setContentView(img);
}
}