Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Added a Toast when the Activity starts. Added a click listener to the…
Browse files Browse the repository at this point in the history
… ListView that displays a Toast with the item position in the list
  • Loading branch information
Sarah Buchanan committed Mar 21, 2017
1 parent 2e63715 commit 0adc2da
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.codeschool.candycoded;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

Expand Down Expand Up @@ -46,5 +50,19 @@ protected void onCreate(Bundle savedInstanceState) {
ListView listView = (ListView)this.findViewById(R.id.list_view_candy);

listView.setAdapter(adapter);

Context context = this;
String text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast newToast = Toast.makeText(MainActivity.this, ""+i, Toast.LENGTH_SHORT);
newToast.show();
}
});
}
}

0 comments on commit 0adc2da

Please sign in to comment.