Android 개발의 그리드보기에서 선택한 항목을 가져 오려고합니다. 클릭 리스너에클릭 수신기의 Android 그리드보기 선택한 항목 받기
private static Integer[] iconlist = {
R.drawable.food_icon, R.drawable.transport_icon, R.drawable.entertainment_icon,
R.drawable.bill_icon, R.drawable.others_icon, R.drawable.salary_icon,
R.drawable.investment_icon, R.drawable.bonus_icon, R.drawable.medication_icon,
R.drawable.drinks_icon, R.drawable.car_icon, R.drawable.mask_icon,
R.drawable.shopping_icon, R.drawable.lottery_icon, R.drawable.pet_icon,
R.drawable.movie_icon, R.drawable.plant_icon, R.drawable.paint_icon,
};
그리고있는 gridview : : 여기 그리드 뷰를 채우는 데 사용 당김의 목록입니다
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View v, int position, long id) {
Toast.makeText(getActivity(), "Grid Item " + (position + 1) + " Selected", Toast.LENGTH_LONG).show();
int selected = position + 1;
for(int i = 0; i < iconlist.length; i++){
if(iconlist[i] == selected){
}
}
}
});
내가 클릭에 따라 올바른 정수 위치를 얻을 수 있었다. 내가 뭘 하려는지 선택한 drawable 기반으로, 문자열을 추출하려고합니다.
예를 들어 전송 아이콘을 클릭하면 "R.drawable.transport_icon"에서 "transport_icon"문자열을 가져 와서 문자열로 저장하려고합니다. 그러나 어떻게해야할지 모르겠습니다.
아이디어가 있으십니까?
이 유 문자열로 "" "R.drawable.transport_icon을"이 저장 하시겠습니까? –
아니요, "transport_icon"을 문자열로 저장하려고합니다. – hyperfkcb
첫 번째 제거 위치는 선택한 항목을 가져 오는 +1입니다. iconList도 0 위치부터 시작합니다. –