android custom toast for a gridview picture that says first name

337 views Asked by At

for an android project, I am required to have an android custom toast for a picture in a gridview that will say the person's first name when I click on their photo. Here is a code snippet

public class MainActivity extends Activity {
 
 Integer[]  Friends = {R.drawable.joel, R.drawable.brandi, R.drawable.augusta, R.drawable.demarc, R.drawable.branndon, 
   R.drawable.abby,R.drawable.solomon, R.drawable.sunny, R.drawable.brandi};
   ImageView pic;
   
   
 

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  GridView gr = (GridView)findViewById(R.id.gridView1);
  final ImageView pic = (ImageView) findViewById(R.id.imgLarge);
  gr.setAdapter(new ImageAdapter(this));
  gr.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> arg0, View arg1, 
     int arg2, long arg3) {
    // TODO Auto-generated method stub

Toast.makeText(getBaseContext(), "Friend Pucture Selected is " + (arg2 + 1), Toast.LENGTH_SHORT).show();
    pic.setImageResource(Friends[arg2]);
    
   
   }
  });

   
 }

Any help? Our book doesn't really help with this part. It just will have the string message and then the arg2 number specifying what number photo it is.

0

There are 0 answers