-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathImageViewChangeResourceId.java
More file actions
26 lines (23 loc) · 1.25 KB
/
ImageViewChangeResourceId.java
File metadata and controls
26 lines (23 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//class that sends the resource id
int[] ids = {R.id.textViewContact_1,R.id.textViewContact_2,R.id.textViewContact_3,R.id.textViewContact_4,R.id.textViewContact_5};
int[] avatarsIds= {R.drawable.luke,R.drawable.obi_wan,R.drawable.yoda, R.drawable.darth_vader, R.drawable.darth_maul};
for(byte i=0;i<ids.length;i++) {
int id=ids[i];
int avatarId=avatarsIds[i];
findViewById(id).setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
TextView tv = (TextView) v;
Intent myIntent = new Intent(getBaseContext(), ConversationActivity.class);
myIntent.putExtra("userName", tv.getText().toString());
myIntent.putExtra("imageResourceId", avatarId);
startActivity(myIntent);
}
}
);
}
//class that receives the resource id
int imageResourceId= getIntent().getIntExtra("imageResourceId",0);
Bitmap bitmap= BitmapFactory.decodeResource(getResources(), imageResourceId);
ImageView iv= (ImageView) findViewById(R.id.imageViewContact);
iv.setImageBitmap(bitmap);