Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit bd57648

Browse files
sdspikesLyla
authored andcommitted
3.01 Add toast on item click
1 parent 2141b9c commit bd57648

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

app/src/main/java/com/example/android/sunshine/app/ForecastFragment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
import android.view.MenuItem;
2828
import android.view.View;
2929
import android.view.ViewGroup;
30+
import android.widget.AdapterView;
3031
import android.widget.ArrayAdapter;
3132
import android.widget.ListView;
33+
import android.widget.Toast;
3234

3335
import org.json.JSONArray;
3436
import org.json.JSONException;
@@ -112,6 +114,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
112114
// Get a reference to the ListView, and attach this adapter to it.
113115
ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
114116
listView.setAdapter(mForecastAdapter);
117+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
118+
119+
@Override
120+
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
121+
String forecast = mForecastAdapter.getItem(position);
122+
Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show();
123+
}
124+
});
115125

116126
return rootView;
117127
}

0 commit comments

Comments
 (0)