0
我試圖讓電影海報長廊,在gallerry用戶點擊的項目,會出現圖像標題時,訪問對象屬性。如何從內部OnItemClickListener
我使用的自定義ArrayAdapter與grideview
MoviePoster類如下鏈接圖片:
public class MoviePoster {
String title;
int image;
public MoviePoster(int image, String title) {
this.image = image;
this.title = title;
}
public MoviePoster(){
}
}
這裏是MainACtivity和圖像列表。
public class MainActivityFragment extends Fragment {
private MovieAdapter movieAdapter;
MoviePoster[] posters ={
new MoviePoster(R.drawable.ironman, "ironman"),
new MoviePoster(R.drawable.jobs, "jobs"),
new MoviePoster(R.drawable.superman,"superman"),
new MoviePoster(R.drawable.terminator, "terminator"),
new MoviePoster(R.drawable.batman, "batman"),
new MoviePoster(R.drawable.linux, "linux"),
new MoviePoster(R.drawable.madara, "madara"),
};
public MainActivityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
movieAdapter = new MovieAdapter(getActivity(), Arrays.asList(posters));
GridView gridView = (GridView) rootView.findViewById(R.id.MoviesGrid);
gridView.setAdapter(movieAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getActivity(), "need to show image title here???",Toast.LENGTH_LONG).show();
}
});
return rootView;
}
}
我只是不知道如何記得每個項目的圖像標題。誰能幫忙?
'MoviewPoster海報=(MoviewPoster)adapterView.getItemAtPosition(位置);' – Blackbelt
請你解釋一下,我在哪裏可以使用此行代碼? @Blackbelt –
你能證明你的適配器類@Mohamed易卜拉欣 –