그래서 클래스는 다음과 같습니다 BaseAdaper을 확장했다 : 내 활동에안드로이드에서 GridLayout과 컨텍스트 메뉴를 표시하는 방법
public class ProfileTileAdapter extends BaseAdapter {
private Context context;
private ForwardingProfile[] profiles;
public ProfileTileAdapter(Context context, ForwardingProfile[] profiles) {
this.context = context;
this.profiles = profiles;
}
@Override
public int getCount() {
return profiles.length;
}
@Override
public Object getItem(int position) {
return profiles[position];
}
@Override
public long getItemId(int position) {
return profiles[position].getID();
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
ProfileTile tile = null;
if (convertView == null) {
tile = new ProfileTile(context, profiles[position]);
LayoutParams lp = new GridView.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
tile.setLayoutParams(lp);
} else {
tile = (ProfileTile) convertView;
}
return tile;
}
}
A A GridLayout과를 가지고 있고 그것의 어댑터를 설정 ProfileTileAdapter의 인스턴스 내 활동에서 사용자가 오랫동안 뷰 (이 경우 ProfileTile) 중 하나를 길게 누르면 상황에 맞는 메뉴를 열고 싶지만 어떻게해야할지 모르겠다. 또한 사용자가 컨텍스트 메뉴에서 옵션을 선택할 때 길게 눌러 진 ProfileTile을 찾아야합니다. 모든 자습서는 액티비티의 정적 뷰를 사용하여 계속 수행하지만 이와는 다릅니다.